tutorcruncher / django-jinja-bootstrap-form Goto Github PK
View Code? Open in Web Editor NEWdjango-jinja-bootstrap-form
License: BSD 3-Clause "New" or "Revised" License
django-jinja-bootstrap-form
License: BSD 3-Clause "New" or "Revised" License
README says 1.8, setup.py says 3+. Which one is it?
Here is what I get for default login form:
<label class="control-label {{ no such element: django.contrib.auth.forms.AuthenticationForm object['required_css_class'] }}" for="id_username">Username</label>
Hi there,
Thanks for making this library.
I was expecting to use the lib by simply pip installing it and adding bootstrapform_jinja
to INSTALLED_APPS
, but unfortunately this plug-in-and-play doesn't seem to work in my environment.
I got the following 2 issues:
bootstrap
, etc ) are not registered to the Jinja Environment
object, which caused the error ("No filter named 'bootstrap'.",)
bootstrapform_jinja
was not processed by the Jinja backend, which caused the error Invalid block tag on line 1: 'import'. Did you forget to register or load this tag?
My Jinja configuration was based on the example in the Django official doc here
https://docs.djangoproject.com/en/4.1/topics/templates/#django.template.backends.jinja2.Jinja2
from django.templatetags.static import static
from django.urls import reverse
from jinja2 import Environment
def environment(**options):
env = Environment(**options)
env.globals.update({
'static': static,
'url': reverse,
})
return env
And this environment was registered in the Django TEMPLATES
settings like
TEMPLATES = [
{
'BACKEND': 'django.template.backends.jinja2.Jinja2',
...
'OPTIONS': {
'environment': '__path_to_the_above_file__.environment',
...
},
},
...
]
To solve 1st issue, I tried attaching the internal filters to the env
returned, like this
from django_jinja.library import _update_env
def environment(**options):
env = Environment(**options)
# ...
_update_env(env)
return env
Now came the 2nd error. This time I tried adding the path of bootstrapform_jinja/templates
in TEMPLATES
, like this
TEMPLATES = [
{
'BACKEND': 'django.template.backends.jinja2.Jinja2',
'DIRS': ['/absolute/path/to/venv/site-packages/bootstrapform_jinja/templates',
'TEMPLATES FOLDER OF OTHER APPS', ...],
},
...
]
And now it works. Though, neither of those changes looks good to be pushed into production environment.
Wonder how I was supposed to use this library. Any help is appreciated.
UPDATE:
I was using Python 3.9.7, along with
asgiref==3.5.2
Babel==2.10.3
Django==4.1.1
django-filter==22.1
django-jinja==2.10.2
django-jinja-bootstrap-form==4.3.5
Jinja2==3.1.2
MarkupSafe==2.1.1
pytz==2022.2.1
sqlparse==0.4.2
template:
bootstrapform/form.jinja
was not found.
I'm using Django 1.11.4 all the packages are at the latest version.
Not really sure from where this error arise...
{% csrf_token %}
{{ form|bootstrap_inline }}
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
The README says "Python >=3.5", but the setup.py says 3.8 only. Which is the supported version range?
It would be easier to install and keep track of requirements with pip.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.