1

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 ?

3
  • 1
    It would help if you'd elaborate a bit on what exactly you are trying to do. Commented Nov 27, 2011 at 22:40
  • i want to use my login.html login.html is in templates directory but i got this error :S Commented Nov 27, 2011 at 22:41
  • can you please paste here your settings file? Commented Nov 27, 2011 at 22:50

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

i take only ">" as an output :S
its name is login but index page :D
what the meaning of ">" in browser i see ">" this as output

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.