Django 管理模板

发布于 2024-11-08 20:08:48 字数 4249 浏览 0 评论 0原文

我有一个类似于:

class Address_info_updateForm(forms.Form):
    street = forms.CharField(label=_("Street"), required=True)
    street2 = forms.CharField(label=_("Additional Address"), required=False, max_length=50)
    zip = forms.CharField(label=_("Postcode"), required=True, max_length=50)

    city = forms.CharField(label=_("City"), required=True, max_length=50)
    state = forms.CharField(label=_("State"), required=False, max_length=50)        
    country = forms.ChoiceField(label=_("Country"), choices=countries, widget=forms.Select,    required=True)  

现在我已经渲染到模板,就像:

{% extends "base/base_page.html" %}
{% load i18n %}
{% load static %}

{% block html_title %}
    {% trans "Update Profile" %}                    
{% endblock %}

{% block html_page_left_content %}


<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="stepcarousel.js">

stepcarousel.setup({
  galleryid: 'mygallery2', //id of carousel DIV
  beltclass: 'belt2', //class of inner "belt" DIV containing all the panel DIVs
  panelclass: 'panel2', //class of panel DIVs each holding content
  autostep: {enable:true, moveby:1, pause:3000},
  panelbehavior: {speed:500, wraparound:false, wrapbehavior:'slide', persist:true},
  defaultbuttons: {enable: true, moveby: 1, leftnav: ['{{ STATIC_PREFIX }}images/home/bigarrowleft.png', 5, 168], rightnav: ['{{ STATIC_PREFIX }}images/home/bigarrowright.png', -47, 163]},
  statusvars: ['statusA', 'statusB', 'statusC'], //register 3 variables that contain current panel (start), current panel (last), and total panels
  contenttype: ['inline'] //content setting ['inline'] or ['ajax', 'path_to_external_file']
})


</script>

<div style="height: 400px">
    <div>
        <p class="title">{% trans "BILLING ADDRESS" %}</p>
    </div>
    <form action="" method="POST" class="custom_form">{% csrf_token %}
        <table style="color:black;text-align:left; margin-left: 20px;">

           {% if form.errors %}
                                       <span style="color:red;">{% trans "You have not filled in the form correctly. Please correct the errors"%}:</span>                                                                                              
                        {% endif %}
                        {% for field in form %}
                             {% if not field.is_hidden %}        
                            <tr>
                                    <td>                                                        
                                            {{field.label}}                                                        
                                            {% if field.field.required %}
                                            <span style="color:red;">*</span>
                                            {%endif%}
                                    </td>                                                
                            </tr>
                            {%else%}                        
                                {{field}}{{field.errors}}                                                   
                            {%endif%}
                        {% endfor %}
            <tr>
                <td colspan="2">
                    <input type="submit" value="{% trans "UPDATE" %}">
                    <input type="button" value="{% trans "CANCEL" %}" onclick="document.location.href='{{base_url}}MyProfile/'" class="custom_button">
                </td>
            </tr>
        </table>
    </form>                    
    <script>
        jQuery('select#id_country').wrap('<div class="select_div" />');
    </script>
</div>
{% endblock %}
{% block html_page_right_sidebar_login %}
{% endblock %}

问题是当我使用 {{form.as_table}} 我看到我的文本框以及我的表单字段非常下降方式。 但是,当我使用 stepcruousel 显示错误和 * 标记的字段时,它不会向我显示文本框,而只会向我显示带有 aestrics * 的字段,例如

Street * 等等,

我想要字段也与文本框一起成为 aestrix。

提前致谢

I have a form which is like:

class Address_info_updateForm(forms.Form):
    street = forms.CharField(label=_("Street"), required=True)
    street2 = forms.CharField(label=_("Additional Address"), required=False, max_length=50)
    zip = forms.CharField(label=_("Postcode"), required=True, max_length=50)

    city = forms.CharField(label=_("City"), required=True, max_length=50)
    state = forms.CharField(label=_("State"), required=False, max_length=50)        
    country = forms.ChoiceField(label=_("Country"), choices=countries, widget=forms.Select,    required=True)  

Now I have rendered to template which is like:

{% extends "base/base_page.html" %}
{% load i18n %}
{% load static %}

{% block html_title %}
    {% trans "Update Profile" %}                    
{% endblock %}

{% block html_page_left_content %}


<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="stepcarousel.js">

stepcarousel.setup({
  galleryid: 'mygallery2', //id of carousel DIV
  beltclass: 'belt2', //class of inner "belt" DIV containing all the panel DIVs
  panelclass: 'panel2', //class of panel DIVs each holding content
  autostep: {enable:true, moveby:1, pause:3000},
  panelbehavior: {speed:500, wraparound:false, wrapbehavior:'slide', persist:true},
  defaultbuttons: {enable: true, moveby: 1, leftnav: ['{{ STATIC_PREFIX }}images/home/bigarrowleft.png', 5, 168], rightnav: ['{{ STATIC_PREFIX }}images/home/bigarrowright.png', -47, 163]},
  statusvars: ['statusA', 'statusB', 'statusC'], //register 3 variables that contain current panel (start), current panel (last), and total panels
  contenttype: ['inline'] //content setting ['inline'] or ['ajax', 'path_to_external_file']
})


</script>

<div style="height: 400px">
    <div>
        <p class="title">{% trans "BILLING ADDRESS" %}</p>
    </div>
    <form action="" method="POST" class="custom_form">{% csrf_token %}
        <table style="color:black;text-align:left; margin-left: 20px;">

           {% if form.errors %}
                                       <span style="color:red;">{% trans "You have not filled in the form correctly. Please correct the errors"%}:</span>                                                                                              
                        {% endif %}
                        {% for field in form %}
                             {% if not field.is_hidden %}        
                            <tr>
                                    <td>                                                        
                                            {{field.label}}                                                        
                                            {% if field.field.required %}
                                            <span style="color:red;">*</span>
                                            {%endif%}
                                    </td>                                                
                            </tr>
                            {%else%}                        
                                {{field}}{{field.errors}}                                                   
                            {%endif%}
                        {% endfor %}
            <tr>
                <td colspan="2">
                    <input type="submit" value="{% trans "UPDATE" %}">
                    <input type="button" value="{% trans "CANCEL" %}" onclick="document.location.href='{{base_url}}MyProfile/'" class="custom_button">
                </td>
            </tr>
        </table>
    </form>                    
    <script>
        jQuery('select#id_country').wrap('<div class="select_div" />');
    </script>
</div>
{% endblock %}
{% block html_page_right_sidebar_login %}
{% endblock %}

the problem is when i use {{form.as_table}} i see my textboxes along with my form fields in very descent manner.
But when i am using the stepcruousel to display the errors and * marked fields it is NOT SHOWING ME THE TEXTBOXES and it is only showing me the fields with aestrics * like this

Street * and so on

I want the fields to be aestrix along with the texboxes also.

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟花易冷人易散 2024-11-15 20:08:48

显示字段标签和您正在使用的文本框:

{{field.label}}                                                        
{% if field.field.required %}
<span style="color:red;">*</span>
{%endif%}

但这只会显示标签 {{field.label}} 而不是文本框,因为没有 {{ field }} 这是翻译为字段 html 的小部件(在您的情况下是文本框)。添加它:

{{field.label}}                                                        
{% if field.field.required %}
<span style="color:red;">*</span>
{%endif%}
{{ field }}

To show the field label & textbox you are using:

{{field.label}}                                                        
{% if field.field.required %}
<span style="color:red;">*</span>
{%endif%}

but this will show only label {{field.label}} but not textbox because there is no {{ field }} which is the widget translated to html of the field (in your case its the text box). Add it:

{{field.label}}                                                        
{% if field.field.required %}
<span style="color:red;">*</span>
{%endif%}
{{ field }}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文