У меня проблема Django материализовать css форму при рендеринге формы, которую я получаю, переменная не существует из поля. html из django -materialize css -form - PullRequest
0 голосов
/ 19 июня 2020

Я новичок в Django. всякий раз, когда я визуализирую форму, я получаю сообщение «Произошло исключение: VariableDoesNotExist Неудачный поиск ключа [required_css_class] в». Я не понимаю эту ошибку, если кто-нибудь объяснит или скажет мне, что я делаю неправильно, будет очень признателен

заранее спасибо

это мое мнение

def considerations(request):        

    if request.method == "POST":
        form = B2bConsideration(request.POST)
        v = form.is_valid() 
        if form.is_valid():
            instance = form.save(commit=True)
            #adding date to instance from request not in table but a good idea
            #instance.date = request.date
            instance.save()
            return HttpResponseRedirect(reverse('b2b:TypeOfTitle'))  
        else:
            return HttpResponse(form.errors)
    else:
        form = B2bConsideration()
        return render(request, 'b2b/B2B_notes.html',{'form':form} )

это моя модель

class B2bConsideration(ModelForm):
CHOICES = [('yes_title_under_name', 'yes'),('No_title_under_name','no'),]
under_name_title = forms.ChoiceField(choices=CHOICES, widget=forms.RadioSelect())
class Meta:
    model = Consideration
    fields = ['under_name_title','salvage_title','is_title_paidoff']

это моя модель

under_Name_choices = [('yes_title_under_name', 'yes'),('No_title_under_name','no'),]
salvage_title_choices =[('yes_salvage_title','yes'),('no_salvage_title','no'),]
is_title_paidoff_choices = [('yes_title_paidoff', 'yes'),('no_title_paidoff','no'),]

class Consideration (models.Model):
    under_name_title = models.CharField(max_length=21, choices=under_Name_choices)
    salvage_title = models.CharField(max_length=18, choices=salvage_title_choices)
    is_title_paidoff = models.CharField(max_length=21, choices=is_title_paidoff_choices)

вот на что указывает ошибка. это то, что он сказал "Произошло исключение: VariableDoesNotExist Неудачный поиск ключа [required_css_class] в"

 <label class="control-label {{ classes.label }} {% if field.field.required %}{{ form.required_css_class }}{% endif %}">{{ field.label }}</label>

это мой HTML

{% load static %}
  {% load materializecss %}
<!DOCTYPE HTML>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Titlemax B2B</title>
    {% block css %}
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/css/materialize.min.css">
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    {% endblock css %}
    {% block javascript %}
    <script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/js/materialize.min.js"></script>
    {% endblock javascript %}



     <script src="{% static 'B2B_index.js' %}"></script> 
    <link rel="stylesheet" href="{% static 'B2B_index.css' %}">

</head>

{{ form.under_name_title.0}}
{{ form.under_name_title.1}}

{{ form|materializecss:'m6' }}

1 Ответ

0 голосов
/ 19 июня 2020
• 1000 :
return render(request, 'b2b/B2B_notes.html',{'my-form':form} )

Не забудьте также переименовать переменную в вашем html в последних 3 строках, где вы вызываете {{form}}

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...