Django登录网址

问题描述 投票:1回答:1

如何在个人页面登录后启用重定向用户,包括user.id,如http://mysite/client/12。我添加了应用程序client

URLs.朋友

from django.conf.urls import url
from . import views

app_name = 'client'
urlpatterns = [
    url(r'^(?P<user_id>\d+)/$', views.user_profile, name='user_profile'),    
]

views.朋友

from django.shortcuts import render
from django.contrib.auth.decorators import login_required

@login_required
def user_profile(request,user_id):
    user_id = request.user.id
    return render(request, 'client/profile.html')

并在settings.py中更改

LOGIN_REDIRECT_URL = 'client:user_profile request.user.id'

现在,当我单击LogIn时,我收到错误

Unsafe redirect to URL with protocol 'client'

我认为我并没有试图正确解决这个问题。

django
1个回答
3
投票

LOGIN_REDIRECT_URL应该是一个URL,例如LOGIN_REDIRECT_URL = '/accounts/profile/'

检查文档here

因为你正在做'client:user_profile request.user.id',看起来系统正试图将client确定为像httphttps这样的协议。

© www.soinside.com 2019 - 2024. All rights reserved.