当登录过程完成后,我正在尝试将用户重定向到他们的个人资料页面,我将用户ID传递给网址,尽管我收到以下错误。
反转'指数'参数'(2,)'未找到。尝试过1种模式:[u'个人资料/个人资料/(?P / d +)/ $']
登录重定向
return redirect('profiles:index',user.id)
url表达
url(r'^profile/(?P<user_id>/d+)/$', views.index, name='index'),
登录视图
def Login(request):
form = LoginForm()
regForm = SignUpForm()
if request.method == 'POST':
user = authenticate(username=request.POST['login_username'], password=request.POST['login_password'])
if user is not None:
login(request, user)
if 'next' in request.POST:
return redirect(request.POST['next'])
#print '----------------------'
#print user.id
return redirect('profiles:index',user.id)
else:
return render(request, 'index.html',{'error':'The username and password didnt match','form':form,'regForm':regForm})
else:
return render(request, 'index.html',{'form':form,'regForm':regForm})
主要网址
from django.contrib import admin
from authentication import views
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$', views.index, name="index"),
url(r'^authentication/', include('authentication.urls')),
url(r'^emails/', include('emails.urls')),
url(r'^profiles/', include('profiles.urls')),
]
答案 0 :(得分:0)
您的网址格式中存在拼写错误。您应该在正则表达式中使用 \d+
来匹配数字(请注意反斜杠)。
url(r'^profile/(?P<user_id>\d+)/$', views.index, name='index'),
答案 1 :(得分:0)
使用以下代码:
url(r'^profiles/', include('profiles.urls', namespace='profile')), # add namespace to your route