- Notifications
You must be signed in to change notification settings - Fork89
The code that powers djangosnippets.org, it allows users to post and share useful "snippets" of code.
License
django/djangosnippets.org
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This code is used to power the snippet sharing site,djangosnippets.org
- Python version 3.11
- PostgreSQL
- uv - An extremely fast Python package and project manager
Clone the repo:
https://github.com/django/djangosnippets.org.gitInstall uv if you haven't already:
#macOScurl -LsSf https://astral.sh/uv/install.sh | sh#Windowspowershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
Connect 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 dependencies:
uv sync --extra devCopy .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:
uv run python manage.py migrateOptionally load data first:
uv run python manage.py loaddata fixtures/cab.jsonCreate superuser:
uv run python manage.py createsuperuserInstall tailwind (npm is required):
uv run python manage.py tailwind installRun server locally:
uv run python manage.py runserver_plusRun tailwind in another terminal locally:
uv run python manage.py tailwind start
UsingDocker 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.3GunicornRedis
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 theFoundation framework as the core of its visual style. Toget this working on your local machine you needcompass andbower to compileyour stylesheets. Pleasenever modify the generated .css files directly. Use the .scss ones instead.
To keep the setup path as short as possible, run the following commandsin your terminal:
$ cd djangosnippets/static$ bower install && compass watch
If you don't have either of these two installed, you can find detailedinstructions on their respective websites.
Please make sure that you commit only a compressed version of the CSS fileas this is what will be deployed. (In order to do that the defaultconfiguration inside djangosnippets/static/config.rb isoutput_style = :compressed)
The production setup is currently tailored to Heroku and, therefore, mostlyautomatic. The difference between these two setups is configured inthedjangosnippets.settings.production module and therequirements.txt file.
About
The code that powers djangosnippets.org, it allows users to post and share useful "snippets" of code.
Resources
License
Code of conduct
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.