参数传递错误,发生错误。
是动作设置错误吗?url参数设置不正确吗,page_user : {{page_user}} category_id : {{category_num}}正常打印我不知道是不是视图出了问题。
If you kow what is reson thanks for let me know
代码。
<form method="post" action={% url "wm:new_comment_for_skilpage" user_name=page_user category_id=category_num %}>{% csrf_token %}
..
</form>
而网址模式是这样的
path('new_comment_for_skilpage/<str:user_name>/<int:category_id>/' , views.new_comment_for_skilpage, name="new_comment_for_skilpage"),
观点是
def new_comment_for_skilpage(request, pk):
user_name = request.GET.get('user_name')
category_id = request.GET.get('category_id')
if request.method == 'POST':
comment_form = CommentForm(request.POST)
if comment_form.is_valid():
comment = comment_form.save(commit=False)
comment.author = user_name
comment.category_id = category_id
comment.save()
return redirect('/wm/myshortcut/'+user_name+"/"+category_id)
else:
return redirect('/wm/myshortcut/'+user_name+"/"+category_id)
错误。
TypeError: new_comment_for_skilpage() got an unexpected keyword argument 'user_name'
def new_comment_for_skilpage(request, user_name, category_id):
user_name = request.GET.get('user_name')
category_id = request.GET.get('category_id')
if request.method == 'POST':
comment_form = CommentForm(request.POST)
if comment_form.is_valid():
comment = comment_form.save(commit=False)
comment.author = user_name
comment.category_id = category_id
comment.save()
return redirect('/wm/myshortcut/'+user_name+"/"+category_id)
else:
return redirect('/wm/myshortcut/'+user_name+"/"+category_id)