Reputation: 391
I am developing an app for User Registration and Login.I have made the Registration form and now i am now wants to make a login page,for that reason i have made a login.html file and now i want it to be placed in the templates. Thus I create a directory and placed it in that directory home/html/templates/registration/login.html
The Template_dir=() in settings.py file is as:
TEMPLATE_DIRS = (
'/home/html/templates',
)
The view file as
from django.template import loader
from registration.models import Registration
from django.http import HttpResponse
def login(request):
t = loader.get_template('registration/login.html')
return HttpResponse()
But when I am trying to run this file as localhost:8000/registration/login.html I am getting the 404 error Page not found
the url given in url.py file is as:
url(r'^registration/$', 'registration.views.login'),
Upvotes: 1
Views: 126
Reputation: 5864
Django does not serve html files itself. Templates must be rendered and returned as HttpResponse on a view.py.
So try:
from django.shortcuts import render
def login(request):
return render(request, 'registration/login.html')
And localhost:8000/registration/
will return you a login page.
See docs for more info about shortcuts functions and template language
Upvotes: 1
Reputation: 53326
You are getting 404
because you are trying to access localhost:8000/registration/login.html
while you defined url as url(r'^registration/$', 'registration.views.login'),
.
String rather regex in first part in definition in urls.py
should match the URL that you access from browser.
In your case you should access localhost:8000/registration/
.
Also, you should be returning proper http response rather than empty HttpResponse
.
Upvotes: 0