Django中的-success_url配置不正确 [英] Improperly Configured -success_url in Django
问题描述
我对success_url遇到了问题,而不是站点,我看到配置不正确的TemplateResponseMixin需要定义"template_name"或实现"get_template_names()".这是我的views.py:
I've got problem with success_url, rather then site I see an ImproperlyConfigured TemplateResponseMixin requires either a definition of 'template_name' or an implementation of 'get_template_names()'. Here is my views.py:
class CarRentView(SuccessMessageMixin, CreateView):
form_class = CarRentForm
success_url = reverse_lazy('cars')
success_message = "You rent a car"
我的models.py:
my models.py:
class Rental(models.Model):
rentus = models.ForeignKey(User, null=True)
rentcar = models.ForeignKey(Car, null=True)
和forms.py:
CarRentForm类(forms.ModelForm):
class CarRentForm(forms.ModelForm):
class Meta:
model = Rental
fields = '__all__'
和我的网址:
url(r'^car/rent$', CarRentView.as_view(), name = 'rent'),
我想要租房后用户在车位上看到成功消息.
I want to after rent user will see sucess message on carsite.
推荐答案
成功提交表单后,您将重定向到名为 cars
的URL.您尚未显示此视图,但是错误消息告诉您尚未为其设置 template_name
.您应该添加如下内容.
After the form is successfully submitted, you are redirecting to the url named cars
. You haven't shown this view, but the error message is telling you that you haven't set template_name
for it. You should add something like the following.
class CarView(...):
template_name = 'cars.html'
这篇关于Django中的-success_url配置不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!