This is my views.py:
from django.http import HttpResponse
from django.template.loader import get_template
from django.template import Context
def login(request):
t = get_template('login.html')
return HttpResponse(t.render)
In my urls.py I put
(r'^login/', include('project.views.login')),
to show my templates
I set my templates directory in settings.py
But i got an error named
ImportError at /login/
No module named login
What’s wrong ?
includeis used to include other url configs from other apps. It shouldn’t be used if you’re trying to add a url pattern for one particular view. You should have something likeThe other problem is where you return your response.
renderis a method that takes a context (see the docs)In practice, you wouldn’t usually load the template, render it, then return a response. There are two shortcut functions,
renderandrender_to_response, that cut down on repetition.You’ve made a few basic mistakes here. I recommend you work through the Django tutorials (again, if you’ve already looked at them). Tutorial 3 in particular explains all this stuff.