简体   繁体   中英

redirect not working on form submit django 1.6

I am trying to get a responding function to redirect to another page, however, all it seems to do is set the url of the browser and nothing else. I think the login page just reloads too. The page does not reload with new content, no errors are thrown. Here is a snippet of login form page template:

<form id="loginformid" action="/basicsite/loginwithuser/" method="post" enctype="multipart/form-data">
    {% csrf_token %}
    User name: <input type="text" name="username"><br>
    Password: <input type="password" name="pwd"><br>
    <input type="submit" value="login!"/>
</form>

Here is the urls.py:

url(r'^basicsite/loginwithuser', 'basicsite.views.loginwithuser'),
url(r'^basicsite/home', 'basicsite.views.home'),

Here is the views.py

def login(request):
    try:
        userexists = request.session['userexists']
    except:
        userexists = 'notsubmitted'
    return render(request, LOGINPAGETEMPLATE, {'userexists':userexists})

def loginwithuser(request):
    username = request.POST['username']
    passw = request.POST['pwd']

    try:
        u = User.objects.get(user_name=username,password=passw)
        request.session['user'] = u.user_name
        return HttpResponseRedirect('/basicste/home/')
    except:
        request.session['userexists'] = 'incorrectlogin'
        return HttpResponseRedirect('/basicste/login/')

Even when I just try vvv the page does the same behavior:

def loginwithuser(request):
     return HttpResponseRedirect('/basicsite/home/')

I was having an issue with regex: Django form submit url not working

Both urls started with login and basicsite/login was before basicsite/loginwithuser

Does anyone have any advice for forcing literal whole match?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM