Django:url连接到主页面

时间:2014-03-21 16:16:32

标签: django url

我设法登录但我不能在主页(mainView)

只是“您已成功登录!”

mainView有什么问题?

URL

urlpatterns = patterns('',
                     url(r'^$', main_page),
                     url(r'^$', mainView.as_view()), 

视图

def main_page(request):

    state = "Please log in below..."
    username = password = ''
    if request.POST:
        username = request.POST.get('username')
        password = request.POST.get('password')

        user = authenticate(username=username, password=password)
        if user is not None:
            if user.is_active:
                login(request, user)
                state = "You're successfully logged in!"
            else:
                state = "Your account is not active, please contact the site admin."
        else:
            state = "Your username and/or password were incorrect."

    return render_to_response('registration/main_page.html',{'state':state, 'username': username}, context_instance=RequestContext(request))

main_page.html

<form method="post" >
 {% csrf_token %}
    {% if next %}
    <input type="hidden" name="next" value="{{ next }}" />
    {% endif %}
    username:
    <input type="text" name="username" value="{{ username}}" /><br />
    password:
    <input type="password" name="password" value="" /><br />

    <input type="submit" value="Log In" />
</form>

0 个答案:

没有答案