Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
348 views
in Technique[技术] by (71.8m points)

html - How do I change the look of my model fields on the front-end side?

Ideally I want to "expand" my fields on the frontend. They have to be way longer just like when you make them from in the admin-panel. Currently they look like this: enter image description here

However I want them portrayed like this (my admin is bootstrapped btw): enter image description here

Here is my code:

<div class="container">

<h1>Opret ny klient</h1>
<form method="POST" class="post-form">{% csrf_token %}
    {{ form.as_p }}
    <button type="submit" class="btn btn-primary">Opret klient</button>
    <button type="button" class="save btn btn-default">Tilbage til klienter</button>
</form>

</div>

The bottom line How do I make my form seem as visually appealing as it looks in my admin panel?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you looking for fast way, just use crispy forms
http://django-crispy-forms.readthedocs.org/en/latest/install.html#installing-django-crispy-forms

pip install --upgrade django-crispy-forms

in settings.py:
INSTALLED_APPS = ( ... 'crispy_forms', )

at the top of template:
{% load crispy_forms_tags %} and render form like this {% form|crispy %}
it use bootstrap form by default

If you want more options to render your form, you can read docs about crispy. Or just use native django forms, and render each field of this form, like {{ form.your_field }}


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...