Django18初体验


1374 浏览 5 years, 11 months

26 STYLING MVP LANDING PART2

版权声明: 转载请注明出处 http://www.codingsoho.com/

forms.html

  • extend base.html
  • crispy,并修改submit按钮class
  • 添加div,调整宽度和增加title
{% extends "base.html" %}
{% load crispy_forms_tags %}

{% block content %}
<div class="row">
<div class ="col-sm-6 col-sm-offset-3">
{% if title %}
<h1 class = "{% if title_align_center %}text-align-center{% endif %}">{{title}}</h1>
{% endif %}
<form method='POST' action=''>{% csrf_token %}
{{ form|crispy }}

<input class = "btn btn-primary" type='submit' value='Submit' />
</form>
</div>
</div>
{% endblock %}

newsletter\views.py

添加title和对齐的变量

def contact(request):
    title = 'Contact Us'    
    title_align_center = True
 ……
    context = {
        "form": form,
        "title": title,
        "title_align_center": title_align_center,
    }
    return render(request, "forms.html", context)