Twitter bootstrap and crispy forms confusion - django

I decided that I wanted to use twitter bootstrap for a potential website I want to make. However, I am still learning web development. I was wondering if someone could give me and explanation of what Crispy forms has to offer. I've been reading and I believe that it has twitter bootstrap embedded in it? I was wondering which would be a better choice to pick. This might be a bad question to ask but I'm quite confused. Are there pros and cons to picking either?

Twitter bootstrap is something completely different than crispy-forms:
Twitter bootstrap is a CSS and Javascript presentation framework. You can use it to generate your html pages from any framework, not just Django! You can use it to define how your html will be layout in a grid and also it has styles for a number of html components.
Crispy-forms is a Django application that can be used to create better layouts for forms. What it does is that you can define programatically how you want your form to be rendered (instead of doing it in the template with html). You should use it if you want to have really nice looking forms without too much hassle.
The only relation between the two is that crispy-forms actually can render your form using bootstrap layout, meaning that the styles and classes etc of your rendered html form will be following the concepts of the bootstrap framework. I am copying from here http://django-crispy-forms.readthedocs.org/en/latest/install.html#template-packs:
Since version 1.1.0 of django-crispy-forms has built-in support for different CSS frameworks, known as template packs within django-crispy-forms:
* bootstrap Bootstrap is crispy-forms’s default template pack, version 2 of the popular simple and flexible HTML, CSS, and Javascript for user interfaces from Twitter.
* bootstrap3 Twitter Bootstrap version 3.
* uni-form Uni-form is a nice looking, well structured, highly customizable, accessible and usable forms.
* foundation Foundation In creators words “The most advanced responsive front-end framework in the world”. This template pack is externally available through crispy-forms-foundation
So crispy-forms can use a bootstrap mode to render your forms -- but you have to be already using bootstrap in your django templates for this to appear properly!

Related

What are the ways to styling a Django Form?

I was working with Django forms, and to beautify the Django forms I came across widgets, and after learning it got to know that we can customize widgets in two ways:
Using widget instance or
Using widget class.
Later came across django-crispy and django-bootstrap that allow same beautification of the forms along with various other advantages over other.
But I was wondering, how many more such library / packages / apps are there, and is there any short of description for each, which might help me and others too.
Thanks
For simple design or not any extra validation in frontend bootstrap or crispy form is okay.
But if you want to take advantages of custom css js then widget is better option obviously.
I generally do:
create a form using css, js even if in bootstrap
Then pass the classes or id of the particular field in widget

Use django-crispy-forms with Uikit

I'm building a website with django and i'm using uikit 3 as front-end framework is there any way to style django-crispy-forms with uikit ?
with bootstrap i can just put this line on settings file :
CRISPY_TEMPLATE_PACK = 'bootstrap4'
is their any option like this to use uikit ?
You should always check the documentation of the packages you use:
https://django-crispy-forms.readthedocs.io/en/latest/install.html#template-packs
Since version 1.1.0, django-crispy-forms has built-in support for
different CSS frameworks, known as template packs within
django-crispy-forms:
bootstrap Bootstrap is crispy-forms’s default template pack, version 2 of the popular simple and flexible HTML, CSS, and Javascript
for user interfaces from Twitter.
bootstrap3 Twitter Bootstrap version 3.
bootstrap4 Alpha support for Twitter Bootstrap version 4, which is still in Alpha.
uni-form Uni-form is a nice looking, well structured, highly customizable, accessible and usable forms.
foundation Foundation In the creator’s words, “The most advanced responsive front-end framework in the world.” This template pack is
externally available through crispy-forms-foundation

How to render Django forms.ChoiceField as Twitter Bootstrap dropdown

What is the most efficient way (in terms of programming/maintenance effort, elegance) to render a Django forms.ChoiceField as a Twitter Bootstrap dropdown using one of the django-bootstrap, django-bootstrap-form, django-bootstrap-toolkit, django-crispy-forms, etc apps? Is there explicit support for this use case in any of these apps?
Disclaimer I'm the lead developer of <a href="https://github.com/maraujop/django-crispy-forms/"django-crispy-forms (one of the apps mentioned).
I will try to explain how you do this with django-crispy-forms. You simply do in your template:
{% load crispy_forms_tags %}
{{ form|crispy }}
You can see this and more in django-crispy-forms docs. Your ChoiceField will be rendered as Bootstrap dropdown as you want.
Compared to django-bootstrap
First, a little bit of history. django-bootstrap was born after django-uni-form (the parent project from which django-crispy-forms evolved). At that time, django-uni-form was already doing Boostrap forms, but probably not in the best possible way (Bootstrap was supported by using an aditional contrib application). Thus, the author of django-bootstrap probably decided to go on its own.
Now, regarding Bootstrap support. django-bootstrap can also render forms but, instead of using a Django filter, it changes the base class of your form. So django-crispy-forms affects your templates while django-bootstrap affects your Python code.
Also, both django-crispy-forms and django-bootstrap let you do layouts. In django-bootstrap, layouts are in a Meta class within the form while in django-crispy-forms the layouts live in a subclass of FormHelper, which gives you decoupling.
django-bootstrap uses a tuple for defining a layout, while crispy-forms uses a subclass of Layout. This adds the possibility to reuse layouts, compose layouts easily, etc. Note that although crispy's encapsulation still has a list of fields inside, it adds a helpful and human-friendly API to programmatically manipulate the layout and I think enforces a good decoupling pattern.
From what I can see, layouts in crispy-forms are more powerful. It has a larger layout object collection, for example, prepended text, appended text, daterange and others are already supported while in django-boostrap these are in the TODO list.
crispy-forms has also an API for modifying layouts on the go and doing some hardcore programmatic layout building which is very nice.
crispy-forms also supports formsets of all kinds. It supports different CSS template packs, which means that if in the future the new kicking CSS pack is named 'chocolate', it will be very easy to create a new template pack for it and all your forms will be able to be rendered with 'chocolate' without code changes, just a simple setting variable.
crispy-forms also has attributes you can set in FormHelper that define nice extra functionaly you can easily turn on and off. You can also create your own custom attributes if you want.
Finally, django-crispy-forms (together with django-uni-form) has more than 67.000 downloads, which is quite good for a Django application. The project has almost 500 followers in Github, several big users, good testing coverage and several years of history and it's still actively maintained.
Compared to django-bootstrap-form
From what I can see django-bootstrap-form is only a filter for rendering a form with Bootstrap. That is something django-crispy-form covers while offering much, much more. The project was released on 21st August 2012 and looks to me like it's reinventing the wheel because several other apps cover already this use case.
Compared to django-bootstrap-toolkit
It's inspired by django-boostrap-form. From what I see in the docs, it also gives you a filter for rendering a form with Bootstrap. It apparently covers more Bootstrap stuff than forms, but I can't find more info in its docs. Last commit was 2 months ago.
I will insist that I'm obviously not the right person for a comparison that is not biased. That's why I've never written about this before. I could have published a blog post about this several times but I always dismissed the idea. However, as the fragmentation of form apps (and bootstrap-support apps) is growing, I thought this might be a good time to write down what I think.

Is Django design as good without css3 + html 5?

I've had a look at some really good website layout and design using Django, pinterest, (former)curse, disqus, and the django design template lpoks impressive.
Was just pondering thoughts as to were it is necessary to add css3 or html5 to enhance page design and interaction or would using Django features for eg. divs and headers, boxing text good enough or even better visually.
Lets for argument sake, say we are developing an extensive auction site like e-bay or networking site like facebook.
Django doesn't have any design. There is zero front-end included, so that if you made a template page and added divs/headers/whatnot in there it would have absolutely no custom formatting whatsoever beyond the specifications of vanilla HTML.
So if you want to design a site like Pinterest you'll definitely need your own CSS and HTML.
So, django make a view with HTML and CSS (you will have some div..) but no div will be declared and you will have a white page withall things aligned to left..
It is not complicated, if you want a beautiful site (or just not hugly :)) you will need both html and css, but not last versions if you don't wand (but its better..)

django==1.4 support for html5

I have a small blog app I have built using Django 1.4 and recently, I have been learning "bits and pieces" of html5 and css3. I am about the start transitioning my site to html5/css3 and I was wondering if Django widgets support html5(?)
My blog is nothing special - a few forms, a few tables etc.. For example when I do,
{{form_as_p}}
I was wondering if django would generate the required html5 markup(?) I read the docs, and it says the admin pages support html5, but I could not find any docs for regular apps.
If html5 is not supported by Django, what is the best way going about achieving this?
Thanks for your time.
Django's form output is XHTML. Django does not snip with support for the new HTML5 input types such as number, email, url, etc but it is not difficult to add them. See https://code.djangoproject.com/ticket/16630 or https://github.com/rhec/django-html5 That being said I don't know any place where Django generates markup that is invalid for HTML5.
"If html5 is not supported by Django, what is the best way going about achieving this?"
I have been trying a monkeypatch approach with very encouraging results so far, the big bonus for me is that there is no need to change your existing code, or for modifying third party apps, or Django admin. This keeps things very clean and central and there is no need for hairy and repetitive admin.site.register(...)/admin.site.register(...).
https://github.com/danielsokolowski/django-html5monkeypatch