Please take a look at 
https://docs.djangoproject.com/en/stable/howto/legacy-databases/

On Tuesday, September 6, 2016 at 3:16:29 PM UTC-4, MPY wrote:
>
> 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 [email protected].
To post to this group, send email to [email protected].
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/188f9c10-cd36-4e84-9eff-f470d09cedf7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to