Django如何设置Cookie并将其渲染到其他模板?

时间:2018-09-18 11:55:29

标签: python django django-templates django-views django-sessions

我是django的初学者,我了解不多,但是从django文档中进行了仔细研究,但没有想到。我想为我的驱动程序设置cookie。我正在向驱动程序发送一封邮件,其中包含uuid的链接。事情是我通过href将我的驱动程序uuid发布到通过表单在隐藏字段中传递的每个模板上。但我想设置并渲染所有页面,直到确认驾驶员预订。

这些是我的模型,我正在显示我的第一个模板,该模板是通过邮件发送给驱动程序的。当他们在那之后点击链接时,我要在它里面放饼干并在司机预定汽车之后。我想将我为约翰预定的汽车保存在我的数据库中。

Model.py

    driver_firstname = models.CharField(
        max_length=64,
        blank=True,
        null=True
    )
    driver_lastname = models.CharField(
        max_length=64,
        blank=True,
        null=True
    )

    driver_email = models.EmailField(
        blank=True
    )
    driver_token_id = models.UUIDField(
        default=uuid.uuid4,
        unique=True,
        blank=False,
        null=False,
    )

Views.py

@csrf_protect
def rentacar_list(request, page_number=1):
    all_cars = Car.objects.all().order_by('-id')
    if menu_config.menu_item_rentacar_list_show_unavailable == 0:
        all_cars = all_cars.exclude(car_available=0)
    else:
        all_cars = all_cars

    cars_page = Paginator(all_cars, menu_config.menu_item_rentacar_list_pagination)
    args['cars'] = cars_page.page(page_number)
    template = Template.objects.get(template_default__exact=1)
    template_page = template.template_alias + str("/rentacar/rentacar_cars_list.html")
    return render(request, template_page, args)

请帮助我。

0 个答案:

没有答案
相关问题