0

我在每个视图中都使用 @login_decorator('/​​login/') 。每当我尝试访问其他 URL 时,它都会重定向到登录页面。URL变成这样:

http://127.0.0.1:8000/login/?next=/upload_file/

现在,当我输入正确的用户名、密码并单击提交时,什么也没有发生。我仍然在具有相同 URL 的同一页面上。

这是我的form.html:

<form action="/login/" method="post">
{% csrf_token %}
Username: <input type="text" name="username" />
Password: <input type="password" name="password" />
<input type="Submit">

视图.py:

def login_upload(request):
    try:
        if request.method == 'POST':
            usern = request.POST['username']
            unames = ''.join(usern)
            passwo = request.POST['password']
            s = ''.join(passwo)
            h = hashlib.sha1(s).hexdigest()
            db = MySQLdb.connect(user='root', db='galaxy', passwd='devil', host='localhost')
            cursor = db.cursor()
            cursor.execute("SELECT id, username, password FROM galaxy_user where username=%s and password=%s", (unames, h))
            id, compareu, comparep = zip(*cursor.fetchall())
            db.close()

            return HttpResponseRedirect('/upload_file/')
    except ValueError:
            return render_to_response('login.html',  context_instance=RequestContext(request))

网址.py:

urlpatterns = patterns('',

    url(r'^admin/', include(admin.site.urls)),
    url(r'^upload_file/', 'fileupload.views.upload_file'),
    url(r'^sync/', 'fileupload.views.sync'),
    url(r'^login_upload/', 'fileupload.views.login_upload'),
    url(r'^upload_file_form', 'fileupload.views.upload_file_form' ),
    url(r'^book_list', 'fileupload.views.book_list'),
    url(r'^backend/', 'fileupload.backend.show_files')
)
4

1 回答 1

0

您需要在表单中输入“下一个”值

<form action="/login/" method="post">
  {% csrf_token %}
  Username: <input type="text" name="username" />
  Password: <input type="password" name="password" />

  <input type="hidden" name="next" value="{{ next }}" />

<input type="Submit">
于 2013-01-08T09:11:47.390 回答