我有一个简单的模型如下:

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)

根据上面的模型,我在forms.py中生成了一个模型表单,如下所示:

class RatingForm(ModelForm):

     class Meta:
          model = Rating
          exclude = ('from_user', 'dtobject',
                     'shared_object')

在我的URL中,我try 了以下方法:

url(r'^rate/(?P<form_type>[\w]+)/(?P<oid>\d+)/(?P<oslug>[\w-]+)/$', 'rating_form', name='rating_form'),                     

在我看来,有以下几点:

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 })

这样做会导致以下错误:

rating_form() got multiple values for keyword argument 'form_type'

其他详细信息:

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

我做错了什么?

推荐答案

视图的第一个参数应为request

Django相关问答推荐

对象Django API中的对象

Djnago admin中 Select 字段的自定义查询

如何自动删除 Django 模型中的字段值?

访问默认的 django-allauth 登录和注册页面时出现 TemplateSyntaxError

Django 按月分组并按月显示在模板中

从一个组中获取所有用户 - Django

使用 Pytest 在 Django 中编写测试用例时如何加载特定目录中的所有固定装置

使用django提交后如何保留html表单数据?

Django `UniqueConstraint` 异常处理方式与 'unique=True' 相同

带有代码完成功能的 python / django 的 Sublime Text 2 和 3 设置

Django REST Framework如何在序列化程序中引发验证错误时指定错误代码

Django:通过manage.py使用服务器和gunicorn等其他服务器之间的区别.哪个更好?

Django 模板列表的第一个元素

Django 模板:通过扩展模板覆盖包含的子模板块

Django:使用 ModelForm 编辑现有数据库条目

在 Django 中扩展 urlize

清理提交的表单数据中的 HTML

获取 django 应用的绝对路径

刷新时重新提交的django表单

Django:按位置排序,忽略 NULL