This code is used to power the snippet sharing site, djangosnippets.org
- Python version 3.11
- PostgreSQL
Clone the repo:
https://github.com/django/djangosnippets.org.gitCreate your virtual environment:
python -m venv venvActivate in Linux:
source venv/bin/activateActivate in Windows:
venv\Scripts\activateConnect to PostgreSQL
Connect in Linux:
psql -U $(whoami) -d postgresConnect in Windows:
psql -U postgresCreate a PostgreSQL database and role:
postgres=# CREATE DATABASE djangosnippets; postgres=# CREATE USER djangosnippets WITH SUPERUSER PASSWORD 'djangosnippets'; postgres=# GRANT ALL PRIVILEGES ON DATABASE djangosnippets TO djangosnippets;
Exit psql shell:
postgres=# exitInstall requirements:
pip install -r requirements/development.txtCopy .env.template.local file, rename to .env and configure variables for your local postgres database.
Copy in Linux:
cp .env.template.local .envCopy in Windows:
copy .env.template.local .envRun migrations and create superuser:
Migrate:
python manage.py migrateOptionally load data first:
python manage.py loaddata fixtures/cab.jsonCreate superuser:
python manage.py createsuperuserInstall tailwind (npm is required):
python manage.py tailwind installRun server locally:
python manage.py runserver_plusRun tailwind in another terminal locally:
python manage.py tailwind start
Using Docker allows you to set up the development environment more quickly if Docker is installed 🐳
Build the Docker images:
docker compose -f docker-compose.local.yml buildStart the containers:
docker compose -f docker-compose.local.yml up -dGo to: http://127.0.0.1:8000/ and enjoy 🙌
You need to copy .env.example to .env and configure to your needs. The example is fine to start with development.
You may wish to use docker locally for production dependency testing and development; here are the setup instructions:
$ docker-compose -f docker-compose.production.yml build $ docker-compose -f docker-compose.production.yml up -d
-d denotes running docker in a detached state:
$ docker-compose -f docker-compose.production.yml run web python manage.py migrate $ docker-compose -f docker-compose.production.yml run web python manage.py createsuperuser $ docker-compose -f docker-compose.production.yml run web python manage.py loaddata fixtures/cab.json $ npm run build $ docker-compose -f docker-compose.production.yml run web python manage.py collectstatic
The docker setup is running as close as possible to the production setup in Heroku:
Postgres 12.3 Gunicorn Redis
To run our tests with docker:
$ docker-compose -f docker-compose.yml run web python manage.py test --settings=djangosnippets.settings.testing
To run tests:
$ python manage.py test --settings=djangosnippets.settings.testing
DjangoSnippets uses the Foundation framework as the core of its visual style. To get this working on your local machine you need compass and bower to compile your stylesheets. Please never modify the generated .css files directly. Use the .scss ones instead.
To keep the setup path as short as possible, run the following commands in your terminal:
$ cd djangosnippets/static $ bower install && compass watch
If you don't have either of these two installed, you can find detailed instructions on their respective websites.
Please make sure that you commit only a compressed version of the CSS file as this is what will be deployed. (In order to do that the default configuration inside djangosnippets/static/config.rb is output_style = :compressed)
The production setup is currently tailored to Heroku and, therefore, mostly automatic. The difference between these two setups is configured in the djangosnippets.settings.production module and the requirements.txt file.