after a user logs in, he is redirected to transfer.html. however if user has not created any bank account, i d like to redirect him 开发者_运维技巧to createbankaccount.html instead. How do I do that? Here is my code
#login.html
<form action="." method="post" class="login_form">{% csrf_token %}
{{ form.as_p }}
<p class="submit"><button type="submit" name="submit" value="Login">Log in</button></p>
{% if next %}<input type="hidden" name="next" value="{{ next }}">{% endif %}
</form>
#settings.py
LOGIN_REDIRECT_URL = '/main/'
#urls.py
url(r'^main/$',main_home,name='main_home'),
#views.py
#this is the homepage
def main_home(request):
url = '/%s/trans/create' % request.user.username
return HttpResponseRedirect(url)
#I want this to be the homepage if user has no bank account
def mybank_add(request):
url = '/%s/mybank/add' % request.user.username
return HttpResponseRedirect(url)
You're going to have to write your own login method that checks a count of any accounts the logged in user has and then redirect to the view you want.
django.contrib.auth provides everything you need as far as forms and methods to authenticate a user, but it's up to you to check the information you need and redirect.
精彩评论