Hi everyone , I am new with Django and I try to connect with external database to read the data and show in my view.
-- Hi create a new entry in setting.py file with the new database info that I want connect. Something like this.
'externDB': {
'ENGINE': 'django.db.backends.mysql',
'NAME': '*****',
'USER': '*****',
'PASSWORD': '*****',
'HOST': '*****',
'PORT': '',
}
In the View file inside my app I create this to read the info from the database
def index(request):
all_rows = NewModel.objects.using('externDB').all()
return render_to_response('info/index.html', {'rows': all_rows})
But now I obtain this error
global name 'NewModel' is not defined
I undestand the error, I have to include the model, something like that "from info.models import NewModel"
but my model in empty, I don't want to save any data from the model, to my local database, I only want to read then and show in my view.
Any idea , I am missing something with the models, any example that I can read to understand better.
Thanks in advance!You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/52645299-1460-4e15-80f9-d4919046144d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment