Hello my dear programmers,
i am trown into the deep with this project.
i need to build a e-commerce website but a little bit different, this person does not want a checkout cart but a contact form underneath every product with a field for:
name
product
textfield
we need to make it so the SKU of the product on that page gets inserted in the product field.
maybe there is a way to do it with a url instead, that it automaticly pastes the products URL in a textField.
i hope someone can give me some directions i need to look in or some documentation to read.
Django 1.10 Mezzanine CMS Cartridge shop python 2.7
In Django, you can define URLs with regular expressions (as I'm sure you know). So a URL for a product page might look something like this:
url(r'^product/(?P<sku>\d+)$'
When the view is called from this URL, the sku is passed in as a keyword argument to the view. Then, when the template is rendered from the view, you can pass the keyword argument in as a variable:
{{ sku }}
This variable should automatically be included if extending a DetailView (otherwise use get_context_data
).
Therefore, with a little Django templating (perhaps even Javascript), it should be a breeze to prepopulate form fields in your front-end templates with the SKU.
Here are some helpful links:
Django documentation: passing keyword arguments to views