我得到的錯誤視圖registration.views.login沒有返回HttpResponse對象。HttpResponse對象錯誤
我正在創建一個登錄應用程序,我希望當我點擊登錄按鈕主頁顯示給我。
給出然後我得到的頁面錯誤未找到本地主機當我運行view.py:8000 /註冊/ home.html的
from django.template import loader
from django.shortcuts import render
from registration.models import Registration
from django.http import HttpResponse
from django.template import RequestContext
def login(request):
t = loader.get_template('registration/login.html')
return render(request, 'registration/login.html')
的urls.py文件如下:
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^polls/$', 'polls.views.index'),
url(r'^polls/(?P<poll_id>\d+)/$', 'polls.views.detail'),
url(r'^polls/(?P<poll_id>\d+)/results/$', 'polls.views.results'),
url(r'^polls/(?P<poll_id>\d+)/vote/$', 'polls.views.vote'),
url(r'^admin/', include(admin.site.urls)),
url(r'^registration/$', 'registration.views.login'),
,當我嘗試爲運行view.py:
from django.template import loader
from django.shortcuts import render
from registration.models import Registration
from django.http import HttpResponse
from django.template import RequestContext
def login(request):
t = loader.get_template('registration/login.html')
if request.method == "POST":
username = request.POST['user_name']
password = request.POST['password']
user = authenticate(username=username, password=password)
if user is not None:
if user.is_active:
login(request, user)
# success
return render_to_response(request,'registration/login.html')
然後我得到錯誤視圖registration.views.login沒有返回HttpResponse對象。 的urls.py文件保持相同此view.py
@ khalid謝謝!!!! – user786
現在它直接訪問網址 – user786