我正在註冊邏輯,我似乎無法使參數傳入正常工作。我得到的錯誤是找不到404頁面。以前,我也得到了「的觀點沒有返回HttpResponse對象」錯誤任何幫助表示讚賞如何製作一個在Django中傳遞參數的url?
這裏是我的urls.py網址:。
url(r'^accounts/confirm/(?P<activation_key>\d+)/$', 'mysite.views.confirm', name='confirm'),
這是我的views.py :
def confirm(request, activation_key):
if request.user.is_authenticated():
HttpResponseRedirect('/home')
user = Hash.objects.filter(hash_key = activation_key)
if user:
user = Hash.objects.get(hash_key = activation_key)
user_obj = User.objects.get(username= user.username)
user_obj.is_active = True
user_obj.save()
HttpResponseRedirect('/home')
我髮網址,看起來像一個字符串:
"Click the link to activate your account http://www.example.com/accounts/confirm/%s" % (obj.username, activation_key)"
所以鏈接的樣子這樣的:從您的網址結束 http://www.example.com/accounts/confirm/4beo8d98fef1cd336a0f239jf4dc7fbe7bad8849a127d847f
好了,最後的斜線和正則表達式是一個問題,謝謝。現在我得到這個錯誤:視圖mysite.views.confirm沒有返回一個HttpResponse對象。它返回None而不是。有任何想法嗎? – 2014-12-02 19:59:16
這是我得到的同樣的錯誤,當我有正則表達式:accounts/confirm /(?P \ w +)/ $ –
2014-12-02 20:03:15
你實際上沒有返回任何東西。在你有'HttpResponseRedirect('/ home')'的行中,你需要'返回HttpResponseRedirect('/ home')'。 – 2014-12-02 20:05:09