Formularz django otrzymał wiele wartości dla argumentu słowa kluczowego
Mam prosty model w następujący sposób:
RATING_CHOICES = zip(range(1, 6), range(1, 6))
class Rating(models.Model):
value = models.IntegerField(choices=RATING_CHOICES)
additional_note = models.TextField(null=True, blank=True)
from_user = models.ForeignKey(User, related_name='from_user')
to_user = models.ForeignKey(User, related_name='to_user')
shared_object = models.ForeignKey(ObjectDetail, null=True, blank=True)
dtobject = models.DateTimeField(auto_now_add=True)
Z powyższego modelu generuję formularz modelu w moim formularze.py w następujący sposób:
class RatingForm(ModelForm):
class Meta:
model = Rating
exclude = ('from_user', 'dtobject',
'shared_object')
W moich adresach URL próbuję:
url(r'^rate/(?P<form_type>[\w]+)/(?P<oid>\d+)/(?P<oslug>[\w-]+)/I w moich poglądach:
def rating_form(form_type = None, oid = None, oslug=None):
print form_type
form = RatingForm(data=request.POST or None)
if request.POST and form.is_valid():
form.save()
return HttpResponseRedirect("/")
else:
return render(request, "share.html", {'form' : form })
W ten sposób otrzymuję następujący błąd:
rating_form () ma wiele wartości dla argumentu słowa kluczowego „form_type”
Dodatkowe Szczegóły:
Request Method: GET
Request URL: http://127.0.0.1:8000/rate/lending/3/random-stuff/
Django Version: 1.4.1
Exception Type: TypeError
Exception Value:
rating_form() got multiple values for keyword argument 'form_type'
Exception Location: /Library/Python/2.7/site-packages/django/contrib/auth/decorators.py in _wrapped_view, line 20
Python Executable: /usr/bin/python
Co ja robię źle?
, 'rating_form', name='rating_form'),
I w moich poglądach:
def rating_form(form_type = None, oid = None, oslug=None):
print form_type
form = RatingForm(data=request.POST or None)
if request.POST and form.is_valid():
form.save()
return HttpResponseRedirect("/")
else:
return render(request, "share.html", {'form' : form })
W ten sposób otrzymuję następujący błąd:
rating_form () ma wiele wartości dla argumentu słowa kluczowego „form_type”
Dodatkowe Szczegóły:
Request Method: GET
Request URL: http://127.0.0.1:8000/rate/lending/3/random-stuff/
Django Version: 1.4.1
Exception Type: TypeError
Exception Value:
rating_form() got multiple values for keyword argument 'form_type'
Exception Location: /Library/Python/2.7/site-packages/django/contrib/auth/decorators.py in _wrapped_view, line 20
Python Executable: /usr/bin/python
Co ja robię źle?