2

I created a mezzanine projects on a staging host. I found a theme was great for my project looking nice. So i downloaded the theme to my projects and changed theme name in settings.py. I also used mezzanine public accounts application by uncomment it.

Here is the code in settings.py

INSTALLED_APPS = (
"flat",
"django.contrib.admin",
"django.contrib.auth",
...
"mezzanine.accounts",
...
)

That works great. Homepage looks nice. but when i tested the account signup, unfortunately it lost all form labels. I thought it was the static files problem at the first time, so i modified html class label and updated the mezzanine latest css files to the flat app. After many tries, spending lots of time on the problem, it didn't changed anything.

here is the link of theme flat

enter image description here

So i started to focus {% fields_for form %} which i found on templates accounts/account_form.html

{% extends "base.html" %}
{% load i18n mezzanine_tags %}

{% block meta_title %}{{ title }}{% endblock %}
{% block title %}{{ title }}{% endblock %}
{% block body_id %}account{% endblock %}

{% block breadcrumb_menu %}
{{ block.super }}
<li>{{ title }}</li>
{% endblock %}

{% block main %}

{% errors_for form %}

<form method="post"{% if form.is_multipart %} 
enctype="multipart/form-data"{% endif %} role="form" class="center">
    <fieldset class="registration-form">

    {% fields_for form %}

    <div class="form-group">
                    <button type="submit" class="btn btn-success btn-
md btn-block">{{ title }}</button>
                    {% block account_form_actions %}

        {% endblock %}
                </div>
   </fieldset>

Finally, i found the source in ../lib/python3.5/site-packages/mezza nine/core/templates/includes/form_fields.html. It could be the problem of {% if field.label %}<label class="control-label" for="{{ field.auto_id }}">{{ field.label }}</label>{% endif %}

{% load i18n %}
{% load mezzanine_tags %}

{% nevercache %}
<input type="hidden" name="referrer" value="{{ 
request.META.HTTP_REFERER }}">
{% csrf_token %}
{% endnevercache %}

{% for field in form_for_fields %}
{% if field.is_hidden %}
{{ field }}
{% else %}
<div class="form-group input_{{ field.id_for_label }} {{ 
field.field.type }}
    {% if field.errors %} has-error{% endif %}">
    {% if field.label %}<label class="control-label" for="{{ 
field.auto_id }}">{{ field.label }}</label>{% endif %}
    {{ field }}
    {% if field.errors %}
    <p class="help-block">
        {% for e in field.errors %}
        {% if not forloop.first %} / {% endif %}{{ e }}
        {% endfor %}
    </p>
    {% elif field.help_text %}
    <p class="help-block">{{ field.help_text }}</p>
    {% elif field.field.required %}
    <p class="help-block">{% trans "required" %}</p>
    {% endif %}
</div>
{% endif %}
{% endfor %}

{% endblock %}

But before i was going to hack it, i run the command python manage.py collectstatic and python manage.py collecttemplates --noinput to collect mezzanine default static files and templates files to the flat application. It returned default mezzanine theme with correct form labels.

enter image description here enter image description here

|-- __init__.py
|-- deploy
|   |-- crontab.template
|   |-- gunicorn.conf.py.template
|   |-- local_settings.py.template
|   |-- nginx.conf.template
|   `-- supervisor.conf.template
|-- project
|   |-- __init__.py
|   |-- __pycache__
|   |-- dev.db
|   |-- local_settings.py
|   |-- settings.py
|   |-- urls.py
|   `-- wsgi.py
|-- fabfile.py
|-- flat
|   |-- __init__.py
|   |-- admin.py
|   |-- models.py
|   |-- static
|   |-- templates
|   |-- tests.py
|   `-- views.py
|-- gunicorn.conf.py
|-- manage.py
|-- requirements.txt
...
...

Here is my templates setting in settings.py

TEMPLATES = [
    {
        "BACKEND": "django.template.backends.django.DjangoTemplates",
        "DIRS": [
            os.path.join(PROJECT_ROOT, "flat/templates"),
         ...

Now it really really confuse me. I do not know where to start. So would like to ask experts here to help me out. Thanks in advance. I am very grateful to those who can help me or leave me some solutions. Thanks.

pytheworld
  • 49
  • 1
  • 9
  • here is the link of the theme flat [link](https://github.com/von8/mezzanine-themes/blob/master/flat/templates/accounts/account_form.html) – pytheworld Jul 16 '17 at 14:08

1 Answers1

1

I realise this is probably a bit late - but I had the exact same problem with this theme, here's how to fix it:

Assuming you've either downloaded the theme and copied it into your project as an app, or run collecttemplates, Mezzanine's fields_for template tag uses the template at templates/includes/form_fields.html. In my case, I run the template as an app, so it was located at /flat/templates/includes/form_fields.html

The creators of the template have removed the line containing the label: {% if field.label %}<label class="control-label" for="{{ field.auto_id }}">{{ field.label }}</label>{% endif %}

So if you add that line back, you'll get your labels.

RozenMD
  • 325
  • 3
  • 10