开发者

Django - unsupported operand type(s) for %: 'HttpResponseRedirect' and 'unicode'

I have login view:

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')

urls.py

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

template:

  <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>

But i getting:

TypeError at /accounts/login/
unsupported operand type(s) for %: 'HttpResponseRedirect' and 'unicode'

str() function do not help. All usernames could contain only ASCII characters. Does someone know h开发者_如何学Goow to fix this?


why don't you store the string in a variable you'd give to HttpResponseRedirect later?

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜