2012-03-14 1 views
1

등록/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 %}을 (를) 삭제해야했습니다. 입력 필드가 사라 졌나요?츠모 (Satchmo) 템플릿 form.username은 진열하지

내가 한 것은 base.html 템플릿에서 {% block content %} {% endblock %} 및 {% 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> 
... 

답변

0

경우 ... {%의 엔드 블록 %는} "표시"하도록되어 .

{% extends 'base.html' %} 

this won't show up because it's not in a block 

{% block body %} 
    this will "show up" 
{% endblock %} 

은 특정 약 template inheritance

0

대답을 읽기 : 같은 login.html 템플릿에, 그리고

<html> 
    <body> 
     {% block body %} 
     {% endblock %} 
    </body> 
</html> 

:

내가이 base.html 템플릿을 말해봐 사용자 코드

첫 번째 문제는 당신이 아마 메인 템플릿에 수정 단축 등록/login.html을 포함하려한다는 것입니다,하지만 당신은 코멘트에 숨길 :

<!-- I REMOVE REPLACED THE LINK BELOW WITH {% include "registration/login.html" %} --> 

이의 주석이 결과를 볼 수 있습니다.

원본 템플릿 등록/login.html은 accounts.views.emaillogin보기에서 사용되며 /accounts/login/ URL로 사용되며 로그인이 필요한 페이지로 이동하면 리디렉션됩니다. 당신은 부러 뜨 렸지만, 코너의 작은 부분뿐만 아니라이 경우 페이지 중앙에 더 큰 폼을 표시하고 싶습니다. 또한 페이지의 다른 양식과 관련된 오류를 표시하지 않으려 고합니다. 그렇지 않니? 원본 템플릿의 목적을 깨뜨리지 마십시오.

난 당신이 어딘가에 포함하여 작은 템플릿에 로그인 템플릿 registration/login.html의 중요한 부분을 붙여 복사 할 첫 번째 추천 일반 대답. 최소 템플리트에 오류 메시지 등을 포함하지 않도록하십시오. 로그인이 실패하면 메시지가있는 큰 로그인 페이지가 표시됩니다.당신은 action="."

<form method="post" action="{% url auth_login %}?next={{ request.path }}"> 

에주의를 변경해야합니다 : 이름 auth_login은에 의해 satchmo_store/계정/urls.py에 정의되어

(r'^login/$', 'emaillogin', {'template_name': 'registration/login.html'}, 'auth_login'), 

마지막으로 당신이 그것을 만들 수 있습니다 DRY (자신을 반복하지 마십시오)하지만 템플릿은 매우 다른 반면에 그것은 당신에게 가치있는 것은 아닙니다.

[편집 됨] 1) 댓글의 작은 수정 사항이 포함되어 있습니다. 2) 다른 사람들을 위해 더 쉽게 수정되었습니다.

+0

사용자 이름과 비밀번호를 입력 할 때마다

입력 양식을 사용했지만 accounts/login/page로 이동합니다. 그런 다음 로그인 세부 정보를 다시 입력해야합니다. 추신 : 나는 거기에 내 게시물을 업데이 트되었습니다. 어떤 생각? – rushd

+0

내가 달성하고자하는 것은 첫 페이지의 로그인입니다. http://rgmania.com/ – rushd

+0

죄송합니다. '' 리다이렉트하기 위해서는'? next = /'를 리다이렉트 (redirect)해야한다. 나는 대답에서 그것을 고치고있다. – hynekcer

관련 문제