說,在我的註冊類的post方法中,如果用戶已經註冊,我想將用戶重定向到登錄頁面,足夠簡單。Django反向使用kwargs
class Register(View):
...
def post(self, request):
# Some code to check if the email address is already in the db
message = {'message': 'You are already a member and registered the project. Please just log-in',
'registration_date': the_registered_date}# The form with the filled-in data is returned
return HttpResponseRedirect(reverse('accounts:login', kwargs = message))
在我的urls.py:
#urls.py
...
url(r'^login/{0,1}$', Login.as_view(), name='login', kwargs={'message': None, 'date': None}),
這給我的錯誤信息:
Reverse for 'login' with arguments '()' and keyword arguments '{'message': 'You are already a member and registered the project. Please just log-in', 'registration_date': datetime.datetime(2015, 10, 15, 14, 3, 39, 864000, tzinfo=<UTC>)}' not found. 2 pattern(s) tried: [u'accounts/$', u'accounts/login/{0,1}$']
我在做什麼錯?
這看起來不對:'^ login/{0,1} $' – Wtower