Reputation: 1401
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 ?
Upvotes: 1
Views: 187
Reputation: 309099
include
is 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 like
(r'^login/', 'project.views.login'),
The other problem is where you return your response. render
is a method that takes a context (see the docs)
def login(request):
t = get_template('login.html')
c = Context({})
return HttpResponse(t.render(c))
In practice, you wouldn't usually load the template, render it, then return a response. There are two shortcut functions, render
and render_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.
Upvotes: 3