Django application to add the Bulma CSS framework and its extensions
Project description
django-simple-bulma
django-simple-bulma
is a Django application that makes Bulma and Bulma-Extensions available to use in your Django project with as little setup as possible. The goal of this project is to make it as easy as possible to use Bulma with Django.
This project currently uses Bulma v0.9.0 and FontAwesome v5.6.3. If you want features that are only available in newer versions of these frameworks, please create an issue, and we will be happy to update it.
Installation
To get django-simple-bulma
, up and running for your Django project, follow these simple steps:
-
Install it from PyPI with
pip install django-simple-bulma
(or add it to your Pipfile) -
In your Django projects
settings.py
file:- Add
django_simple_bulma
to yourINSTALLED_APPS
INSTALLED_APPS = [ #... 'django_simple_bulma', #... ]
- Add
django_simple_bulma.finders.SimpleBulmaFinder
to yourSTATICFILES_FINDERS
. This normally holds two default handlers that you will probably want to keep, so unless you have any other custom Finders, it should look like this:STATICFILES_FINDERS = [ # First add the two default Finders, since this will overwrite the default. 'django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder', # Now add our custom SimpleBulma one. 'django_simple_bulma.finders.SimpleBulmaFinder', ]
- Add
-
Run
python manage.py collectstatic
command in order to build Bulma and move it to yourstaticfiles
folder. Please note that you will need to use this command every time you make a change to the configuration, as this is the only way to rebuild the Bulma css file. If you are not usingcollectstatic
, read up on it and start using it.This app works fine with Whitenoise, which is a great way to serve static files without needing to mess with your webserver.
django-simple-bulma
should now be working! In order to import it into your template, first load the app with {% load django_simple_bulma %}
, and then use the {% bulma %}
template tag. If you're planning on using icons, you should also import FontAwesome by using {% font_awesome %}
.
<head>
<!-- ... -->
{% load django_simple_bulma %}
{% bulma %}
{% font_awesome %}
<!-- ... -->
</head>
- You're all set! Any Bulma classes you apply should now be working!
Customization
Bulma looks nice by default, but most users will want to customize its look and feel. For this, we've provided a super simple way to change the Bulma variables and to choose which Bulma extensions you want to load into your project.
In order to do this, we'll simply create a dictionary inside your settings.py
called BULMA_SETTINGS
, and configure it there. Here's an example of what that looks like:
# Custom settings for django-simple-bulma
BULMA_SETTINGS = {
"extensions": [
"bulma-collapsible",
"bulma-calendar",
],
"variables": {
"primary": "#000000",
"size-1": "6rem",
},
"output_style": "compressed",
"fontawesome_token": "e761a01be3",
}
You may here define any variable found on the Bulma variables page, and you may use any valid SASS or CSS as the value. For example, hsl(217, 71%, 53%)
would be a valid value for a color variable, as would #ffff00
. Please note that any syntactically incorrect values may prevent Bulma from building correctly, so be careful what you add here unless you know exactly what you're doing.
If the extensions
key is not found, it will default to not loading any extensions. If you want all extensions, simply set it to the string "all"
.
We currently support these extensions:
- bulma-badge
- bulma-calendar
- bulma-carousel
- bulma-collapsible
- bulma-checkradio
- bulma-divider
- bulma-megamenu
- bulma-pageloader
- bulma-pricingtable
- bulma-quickview
- bulma-ribbon
- bulma-slider
- bulma-steps
- bulma-switch
- bulma-tagsinput
- bulma-timeline
- bulma-tooltip
- Cool-Checkboxes-for-Bulma.io (include it as bulma-coolcheckboxes)
If an extension you want to use is missing, feel free to create an issue and we will be happy to add it. Alternatively, add it yourself and create a pull request (see this pr for some context on how to go about doing that).
The output_style
determines the style of the resulting CSS file. It can be any of "nested"
(default), "expanded"
, "compact"
, and "compressed"
. It is recommended to use "compressed"
in production as
to reduce the final file size.
Your fontawesome_token
is the identifier part of your FontAwesome kit src https://kit.fontawesome.com/e761a01be3.js
(not your API token). If you leave out this option, FontAwesome v5.14.0 will be used instead.
Additional scripts
For your convenience, we also give you the option to add other quality of life improvements to your Bulma app. You may want to add these as well if they sound useful to you.
bulma-fileupload
will handle displaying the filename in your file upload inputs.bulma-navbar-burger
will hook up yournavbar-burger
s andnavbar-menu
s automatically, to provide a toggle for mobile users. We use a slightly updated version of the example from Bulma's documentation - simply add adata-target
attribute to yournavbar-burger
that refers to theid
of thenavbar-menu
that should be expanded and collapsed by the button.bulma-notifications
will allow you to close notifications by clicking on the X button.bulma-dropdown
will open/close dropdowns using theis-active
class. It mimics how the dropdowns function on the documentation page.
Additional functionality
If you're writing custom SCSS for your application, django-simple-bulma
does provide a very basic mechanism for compiling
it for you. This is provided because, currently, django-simple-bulma
will cause issues with current Django apps that exist
to compile SCSS for you.
To use this feature, please specify the custom_css
key when defining your BULMA_SETTINGS
. This should be a list
of strings, containing relative paths to .scss
files to be compiled.
BULMA_SETTINGS = {
"custom_scss": [
"myapp/static/css/base/base.scss"
],
}
Please note: The default Django behavior when collecting static files is to keep the containing file structure for
them when they're copied over to the final static files directory. We attempt to do the same thing by parsing the given
path to your .scss
file, using the following strategy:
- If a containing path exists in the
STATICFILES_DIRS
setting, assume that this is the base path to use, and the directory structure below it will be used to contain the resulting.css
file - Otherwise, if the path contains
static/
, assume that the base path ends there and use the rest of the path below it to contain the resulting.css
file.
If both of these strategies fail to figure out what base path to use, an exception will be raised.
Troubleshooting
- If you have the module
sass
installed, please note that it is incompatible with this project. There is a namespace conflict betweensass
andlibsass
which will makedjango-simple-bulma
crash when you attempt to do acollectstatic
. To solve this, just uninstallsass
and uselibsass
instead.
If you run into any other problems with this app, please create an issue, and we will be happy to help you with it. Alternatively, head over to our discord server at https://discord.gg/python and we'll help you figure it out over chat.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-simple-bulma-2.0.0.tar.gz
.
File metadata
- Download URL: django-simple-bulma-2.0.0.tar.gz
- Upload date:
- Size: 16.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.3.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3b142fd174e03e9fd9d0f1659cd20f853252ef3fedf666677a339228111a023 |
|
MD5 | 245648ebe215b0d18361cebebed2431f |
|
BLAKE2b-256 | 8c03b19076d5de5bb0370c00fd3616a4c036f1e1738561771e83a04f8e05489c |
File details
Details for the file django_simple_bulma-2.0.0-py3-none-any.whl
.
File metadata
- Download URL: django_simple_bulma-2.0.0-py3-none-any.whl
- Upload date:
- Size: 14.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.3.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ef76a688a7e14a26cf85249113fee06bdb9fc1179585a8ddec07091d9280a71 |
|
MD5 | 10542ea6d6c01b501d6ee8f584a7f3a3 |
|
BLAKE2b-256 | 41b5ad3f9a2ec205b8cf60fcf03d8f1bb626b964ca913d6a6abae32fd66049c1 |