### views.py ###
def profile_interest_mempick(request,pk,code=None):
"""allows user to subscribe to profile interests"""
me = Register.objects.get(user=request.user)
mem = Register.objects.get(pk=pk)
if code == 's':
interests = mem.profile_interests.all()
if not interests:
content_string = "You currently have nothuing selected"
return render_to_response("homepage/index.html", locals())
else:
content_string = "To unselect an interest please uncheck it's checkbox"
elif code == 'a':
interests = ProfileInterest.objects.all()
if request.method == "POST":
form = profileInterestMemPickForm(request.POST, instance = mem)
if form.is_valid():
form.save()
if Register.objects.get(pk=pk) == Register.objects.get(user = request.user):
return HttpResponseRedirect('/hallo/')
return HttpResponseRedirect('/'.format(pk))
else:
form = profileInterestMemPickForm(instance=me)
form.fields["profile_interest"].queryset = interests
return HttpResponseRedirect('/profile_interest_mempick/')
Traceback:
File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py" in
get_response
111.response = callback(request, *callback_args, Exception **callback_kwargs)
在/ profile_interest_mempick /上键入:TypeError 异常值:profile_interest_mempick()至少需要2个参数(给定1个)
一切似乎都很好,但它一直在抛出这个异常?知道为什么吗?
答案 0 :(得分:0)
检查urls.py上的url正则表达式。
https://docs.djangoproject.com/en/dev/topics/http/urls/
模式应该是:
urlpatterns = patterns('', (r'^ profile_interest_mempick /(?P \ d {4})/ $','news.views.profile_interest_mempick'),
答案 1 :(得分:0)
回溯表明问题不在profile_interest_mempick()的定义中。相反,问题在于其调用者使用了错误数量的参数。