Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django-不支持%的操作数类型:';HttpResponseRedirect';和';unicode';_Django_Url - Fatal编程技术网

Django-不支持%的操作数类型:';HttpResponseRedirect';和';unicode';

Django-不支持%的操作数类型:';HttpResponseRedirect';和';unicode';,django,url,Django,Url,我有登录视图: def login_view(request): username = request.POST['username'] password = request.POST['password'] user = authenticate(username=username, password=password) if user is not None: if user.is_active: login(reque

我有登录视图:

def login_view(request):
    username = request.POST['username']
    password = request.POST['password']
    user = authenticate(username=username, password=password)
    if user is not None:
        if user.is_active:
            login(request, user)
            HttpResponseRedirect('/profile/%s/'%username) 
        else:
            return HttpResponse("Aktywacja konta nie została zakończona")
    else:
        return HttpResponse('invalid login')
url.py

url(r'^login/',
   "social.views.login_view",
   name='login_view'),
模板:

  <form method="post" action="{% url login_view %}">{% csrf_token %}
    <p><label for="id_username">Login:</label> <input id="id_username" type="text" name="username" maxlength="30" /></p>
    <p><label for="id_password">Hasło:</label> <input type="password" name="password" id="id_password" /></p>
    <input type="submit" value="Zaloguj" />
    <input type="hidden" name="next" value="" />
  </form>

str()函数没有帮助。所有用户名只能包含ASCII字符。有人知道如何解决这个问题吗?

为什么不将字符串存储在稍后提供给HttpResponseRedirect的变量中

foo = "/profile/%s/" % username
HttpResponseRedirect(foo)

为什么不将该字符串存储在稍后提供给HttpResponseRedirect的变量中

foo = "/profile/%s/" % username
HttpResponseRedirect(foo)

因为我不知道;我不知道这会有帮助,但它会有帮助。谢谢,因为我不知道;我不知道这会有帮助,但它会有帮助。谢谢。你不应该退回HttpResponseRedirect吗?这个错误看起来像是因为在
%
之前,您在HttpResponseRedirect上有最后一个paren。被接受的答案不会改变任何事情,只是可能让你把paren放在了正确的位置。你不应该返回HttpResponseRedirect吗?这个错误看起来像是因为在
%
之前,您在HttpResponseRedirect上有最后一个paren。被接受的答案不会改变任何事情,只是可能让你把paren放在了正确的位置。