1👍
Yes, you don’t need models for this at all, what you need is a simple django form.
CHOICES = ( (1,"10"), (2,"20"), ...)
class MyForm(forms.form):
...
num_select = forms.ChoiceField(choices = CHOICES)
...
Then in your view
from myapp.forms import MyForm
def my_view(request):
if request.method = 'POST':
form = MyForm(request.POST)
if form.is_valid():
num_select = form.cleaned_data['num_select']
This is of course a rather stripped down version of it, for additional information refer to the link above.
If you don’t want to use a form either, you can just access request.POST
directly, but then what’s the point of using Django? you might as well use PHP
👤e4c5
0👍
You can read raw form data by using HttpRequest.POST
API
https://docs.djangoproject.com/en/1.10/ref/request-response/#django.http.HttpRequest.POST
It’s a dictionary-like object containing all given HTTP POST parameters.
You can just request.POST['num_select']
Remember to include if request.method == 'POST':
before using request.POST
Source:stackexchange.com