Skip to content

django/djangosnippets.org

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

djangosnippets.org

This code is used to power the snippet sharing site, djangosnippets.org

Development Setup

Prerequisites

  • Python version 3.11
  • PostgreSQL

Installation

Basic Installation

  1. Clone the repo:

    https://github.com/django/djangosnippets.org.git
  2. Create your virtual environment:

    python -m venv venv

    Activate in Linux:

    source venv/bin/activate

    Activate in Windows:

    venv\Scripts\activate
  3. Connect to PostgreSQL

    Connect in Linux:

    psql -U $(whoami) -d postgres

    Connect in Windows:

    psql -U postgres
  4. Create 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=# exit
  5. Install requirements:

    pip install -r requirements/development.txt
  6. Copy .env.template.local file, rename to .env and configure variables for your local postgres database.

    Copy in Linux:

    cp .env.template.local .env

    Copy in Windows:

    copy .env.template.local .env
  7. Run migrations and create superuser:

    Migrate:

    python manage.py migrate

    Optionally load data first:

    python manage.py loaddata fixtures/cab.json

    Create superuser:

    python manage.py createsuperuser
  8. Install tailwind (npm is required):

    python manage.py tailwind install
  9. Run server locally:

    python manage.py runserver_plus
  10. Run tailwind in another terminal locally:

    python manage.py tailwind start

With Docker

Using Docker allows you to set up the development environment more quickly if Docker is installed 🐳

  1. Build the Docker images:

    docker compose -f docker-compose.local.yml build
  2. Start the containers:

    docker compose -f docker-compose.local.yml up -d
  3. Go to: http://127.0.0.1:8000/ and enjoy 🙌

Docker

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

Test

To run tests:

$ python manage.py test --settings=djangosnippets.settings.testing

Styling Contributor?

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)

Production Setup

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.

About

The code that powers djangosnippets.org, it allows users to post and share useful "snippets" of code.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 30