注册/login.html 已编辑
{% load i18n %}
<div id="Login">
{% if form.non_field_errors %}
<p class="error">
{% for err in form.non_field_errors %}{{ err }}
{% if not forloop.last %}<br/>{% endif %}
{% endfor %}
</p>
{% endif %}
<form method="post" action=".">{% csrf_token %}
<table>
<tr><td><label for="id_username">{% trans 'USERNAME' %}:</label></td><td>{{ form.username }}</td></tr>
{% if form.username.errors %}<tr><td class="error" colspan="2">***{{ form.username.errors|join:", " }}</td></tr>{% endif %}
<tr><td><label for="id_password">{% trans 'PASSWORD' %}:</label></td><td>{{ form.password }}</td></tr>
{% if form.password.errors %}<tr><td class="error" colspan="2">***{{ form.password.errors|join:", " }}</td></tr>{% endif %}
</table>
<input type="submit" value="{% trans 'sign in' %}" />
{% url registration_register as registration_register %}
{% if registration_register %}
<span><a href="{% url registration_register %}">{% trans "register" %}</a></span>
{% endif %}
<input type="hidden" name="next"
{% if next %}
value={{ next }} />
{% else %}
{% url satchmo_account_info as accounturl %}
{% if accounturl %} value="{% url satchmo_account_info %}" /> {% endif %}
{% endif %}
</form>
{% comment %} We jump through hoops with the urls so it doesn't bomb with django's built in unit tests.{% endcomment %}
{% url auth_password_reset as auth_password_reset %}
{% if auth_password_reset %}
<p>{% trans "If you do not remember your password, please" %}
<a href="{% url auth_password_reset %}">{% trans "click here</a> to have it reset." %}</p>
{% endif %}
</div>
为什么form.username和form.password输入框不显示?我不得不删除块标签 {% extends shop/base.html %}。这是否导致输入字段消失?
我所做的是删除 {% block content %}{% endblock %} 并在 base.html 模板中使用 {% include "registration/login.html" %}。我希望登录部分出现在左上角,而不必为位于 {% block content %} 中的登录字段单击“登录”。
注册/login.html 原始文件
{% extends "shop/base.html" %}
{% load i18n %}
{% block navbar %}
<li class="first"><a href="{{ shop_base }}/">{% trans "Home" %}</a></li>
{% endblock %}
{% block content %}
{% if form.non_field_errors %}
<p class="error">{% for err in form.non_field_errors %}{{ err }}{% if not forloop.last %}<br/>{% endif %}
{% endfor %}</p>
{% endif %}
<form method="post" action=".">{% csrf_token %}
<table>
<tr><td><label for="id_username">{% trans 'Email address' %}:</label></td><td>{{ form.username }}</td></tr>
{% if form.username.errors %}<tr><td class="error" colspan="2">***{{ form.username.errors|join:", " }}</td></tr>{% endif %}
<tr><td><label for="id_password">{% trans 'Password' %}:</label></td><td>{{ form.password }}</td></tr>
{% if form.password.errors %}<tr><td class="error" colspan="2">***{{ form.password.errors|join:", " }}</td></tr>{% endif %}
</table>
<input type="submit" value="{% trans 'Login' %}" />
<input type="hidden" name="next"
{% if next %}
value={{ next }} />
{% else %}
{% url satchmo_account_info as accounturl %}
{% if accounturl %} value="{% url satchmo_account_info %}" /> {% endif %}
{% endif %}
</form>
{% comment %} We jump through hoops with the urls so it doesn't bomb with django's built in unit tests.{% endcomment %}
{% url registration_register as registration_register %}
{% url auth_password_reset as auth_password_reset %}
{% if registration_register %}
<p>{% trans "If you do not have an account, please" %} <a href="{% url registration_register %}">{% trans "click here" %}</a>.</p>
{% endif %}
{% if auth_password_reset %}
<p>{% trans "If you do not remember your password, please" %} <a href="{% url auth_password_reset %}">{% trans "click here</a> to have it reset." %}</p>
{% endif %}
{% endblock %}
商店/base.html
<div id="sidebar-primary">{# rightnav #}
{% block sidebar-primary %}
<h3>{% trans "Quick Links" %}</h3>
{% url satchmo_product_recently_added as recenturl %}
{% if recenturl %}<a href="{{ recenturl }}">{% trans "Recently Added" %}</a>{% endif %}
{% url satchmo_product_best_selling as popularurl %}
{% if popularurl %}<br/><a href="{{ popularurl }}">{% trans "Best Sellers" %}</a><br/>{% endif %}
{% url satchmo_category_index as category_index %}
{% if category_index %} <a href="{{ category_index }}">{% trans "Category Index" %}</a><br /> {% endif %}
{% url satchmo_quick_order as quick_order %}
{% if quick_order %}<a href="{{ quick_order }}">{% trans "Quick Order" %}</a> {% endif %}
{% plugin_point "sidebar_links" %}
<h3>{% trans "Account Information" %}</h3>
{% if user.is_staff %}
<a href="{% url admin:index %}" target="blank">{% trans "Admin" %}</a><br/>
{% endif %}
{% if user.is_authenticated %}
{% url satchmo_account_info as accounturl %}
{% if accounturl %}<a href="{{ accounturl }}" target="blank">{% trans "Account Details" %}</a><br/>{% endif %}
<a href="{{ logout_url }}?next={{request.path}}">{% trans "Log out" %}</a><br/>
{% else %}
<!-- I REMOVE REPLACED THE LINK BELOW WITH {% include "registration/login.html" %} -->
<a href="{{ login_url }}?next={{request.path}}">{% trans "Log in" %}</a><br/>
{% endif %}
{% url satchmo_cart as carturl %}
{% if carturl %}<a href="{{ carturl }}">{% trans "Cart" %}</a>{% endif %}
{% if not cart.is_empty %}
({{ cart_count|normalize_decimal }} - {% if sale %}{{ cart|discount_cart_total:sale|currency }}{% else %}{{cart.total|currency}}{% endif%}) <br/>
{% url satchmo_checkout-step1 as checkouturl %}
{% if checkouturl %}<a href="{{ checkouturl }}">{% trans "Check out" %}</a>{% endif %}
{% endif %}
{% plugin_point "shop_sidebar_actions" %}
{% url satchmo_contact as contact_url %}
{% if contact_url %}<p><a href="{{ contact_url }}">{% trans "Contact Us" %}</a></p>{% endif %}
{% satchmo_language_selection_form %}
{% block sidebar-primary-bottom %}
{% plugin_point "shop_sidebar_primary" %}
{% endblock %}
{% endblock sidebar-primary %}
</div>
我尝试了一个{% include "registration/copy_login.html" %}
并稍微改变了内容。我也用过<form action="{% url auth_login %}
。当我点击提交并填写登录名/密码时,它会将我带到/accounts/login/
我必须再次输入登录数据的地方。
这是我的copy_login.html
:
# copy_login.html
...
<tr><td><label for="id_username">{% trans "Username" %}</label></td><td><input type="text" name="id_username" id="id_username" /></td></tr>
<tr><td><label for="id_password">{% trans "Password" %}</label></td><td><input type="text" name="id_password" id="id_password" /></td></tr>
...