我想获取此选择字段的值。但是没有任何形式。如何在没有任何form.py的情况下获取Django中select字段的值?
<label>Portal Language:</label>
<select name="language">
{% get_available_languages as LANGUAGES %}
{% for lang in LANGUAGES %}
<option>
{{ lang.1 }}
</option>
{% end for %}
</select>
答案 0 :(得分:0)
将它们添加到views.py
views.py
class ClientCreateView(View):
def post(self, request, *args, **kwargs):
language = request.POST.get('language')
答案 1 :(得分:0)
具有更安全版本的功能实现:
在处理此请求的视图中,请像selected_lang = request.POST.get('language', None)
假设您的视图是:
def get_language(request):
selected_lang = request.POST.get('language', None)
#do whatever you want to do with this selected_lang