它在网址页面上显示以下错误 -
反转' views.demo_function'参数'()'和关键字 参数' {' user_name':u' demo_user'}'未找到。 0个图案 尝试过:[]
这是我的' demo_function'在观点中:
def demo_function(request, user_name):
context = RequestContext(request)
profile_dict = {'username':user_name}
render_to_response('project1/profile.html', profile_dict, context)
这是我的功能,其中"反向"方法:
def user_login(request):
context = RequestContext(request)
if request.method == 'POST':
username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password=password)
if user:
if user.is_active:
login(request, user)
#profile(request, username)
return HttpResponseRedirect(reverse('views.demo_function', kwargs={'user_name':username}))
...
...
答案 0 :(得分:0)
尝试使用用户对象而不是使用post变量:
def user_login(request):
context = RequestContext(request)
if request.method == 'POST':
username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password=password)
if user:
if user.is_active:
login(request, user)
#profile(request, username)
return HttpResponseRedirect(reverse('profile', kwargs={'user_name': user.username}))
简单测试,您是否尝试使用有效用户访问此URL(而不是反向):
/home/profile/demo_user/
您可以访问该页面吗?
您可以编辑帖子并添加您的网址文件吗? (项目和应用程序URL)