有没有办法让客户端可以添加特定语言的输入?
Is There A Way That Client Can Add Language Specific Inputs?
我想听取客户的语言意见。例如:
<input type="text" name="title" class="form-control" required="" id="en"> # For English Input
<input type="text" name="title" class="form-control" required="" id="fr"> # For French Input
<input type="text" name="title" class="form-control" required="" id="es"> # For Spanish Input
我想将它们存储为 { 'lang' : 'title', 'lang2' : 'title2', 'lang3' : 'title3' }
对的字典。我使用 Django 作为我的后端。有什么方法可以用 Django 表单做到这一点吗?
编辑:
我试过了,但它似乎不起作用
def get_title(request):
title = {}
if request.method == 'POST':
form = AddFoodCategoryForm(request.POST)
if form.is_valid():
title = { 'fr' : form.cleaned_data.get('Français') }
title = { 'en' : form.cleaned_data.get('English') }
title = { 'ru' : form.cleaned_data.get('Pусский') }
form['title'] = title
form.save()
我将此添加到 forms.py :
def clean(self):
if self.is_valid():
title = { "fr" : self.cleaned_data.get("Français"),
"en" : self.cleaned_data.get("English"),
"ru" : self.cleaned_data.get("Pусский") }
self.cleaned_data['title'] = title
成功了。
我想听取客户的语言意见。例如:
<input type="text" name="title" class="form-control" required="" id="en"> # For English Input
<input type="text" name="title" class="form-control" required="" id="fr"> # For French Input
<input type="text" name="title" class="form-control" required="" id="es"> # For Spanish Input
我想将它们存储为 { 'lang' : 'title', 'lang2' : 'title2', 'lang3' : 'title3' }
对的字典。我使用 Django 作为我的后端。有什么方法可以用 Django 表单做到这一点吗?
编辑: 我试过了,但它似乎不起作用
def get_title(request):
title = {}
if request.method == 'POST':
form = AddFoodCategoryForm(request.POST)
if form.is_valid():
title = { 'fr' : form.cleaned_data.get('Français') }
title = { 'en' : form.cleaned_data.get('English') }
title = { 'ru' : form.cleaned_data.get('Pусский') }
form['title'] = title
form.save()
我将此添加到 forms.py :
def clean(self):
if self.is_valid():
title = { "fr" : self.cleaned_data.get("Français"),
"en" : self.cleaned_data.get("English"),
"ru" : self.cleaned_data.get("Pусский") }
self.cleaned_data['title'] = title
成功了。