Skip to content

Commit 7f828dc

Browse files
committed
Update README with development server setup instructions.
1 parent 397ac26 commit 7f828dc

File tree

5 files changed

+120
-51
lines changed

5 files changed

+120
-51
lines changed

.env.template.local

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
SECRET_KEY=<####SECRET####>
2+
DEBUG=True
3+
ALLOWED_HOSTS=0.0.0.0,127.0.0.1,localhost
4+
DJANGO_SETTINGS_MODULE=djangosnippets.settings.development
5+
SEARCHBOX_SSL_URL=http://elasticsearch:9200/
6+
SESSION_COOKIE_SECURE=False
7+
DATABASE_URL=postgres://djangosnippets:djangosnippets@db/djangosnippets
8+
REDISTOGO_URL=redis://redis:6379/0

README.rst

Lines changed: 107 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3,80 +3,130 @@ djangosnippets.org
33

44
This code is used to power the snippet sharing site, `djangosnippets.org`_
55

6-
Database Setup Using Windows
7-
-----------------------------------
6+
Development Setup
7+
=================
88

9-
Download the latest version of PostgreSQL_. Click on the executable to start the installation setup wizard.
9+
Prerequisites
10+
-------------
1011

11-
Click ``Next``, keeping all the defaults as you work through the wizard. Make a note
12-
of the password you choose for the database superuser (postgres). Select the default port 5432 and the default
13-
locale. After it’s finished installing, you do not need to launch Stack Builder. Un-tick that box if you are asked,
14-
and click ``Finish``.
12+
- Python version 3.11
13+
- PostgreSQL
1514

16-
Open SQL Shell (psql). In the shell, select the default values for Server, Database, Port and Username
17-
(basically, press Enter four times).
15+
Installation
16+
------------
1817

19-
Type in the password you noted earlier and press enter. Run the command below, taking care to include the
20-
semi-colon. ::
18+
1. Clone the repo:
2119

22-
$ CREATE DATABASE djangosnippets;
20+
.. code-block:: console
2321
24-
Close SQL Shell (psql).
22+
https://github.com/django/djangosnippets.org.git
2523
26-
You need to copy .env.example to env.bat and configure to your needs. Use the template below, taking care to
27-
include ``set`` at the start of each line, and to substitute the password you noted earlier into DATABASE_URL.
28-
For development, DEBUG is set to True. ::
24+
2. Create your virtual environment:
2925

30-
set REDISTOGO_URL=redis://redis:6379/0
31-
set SECRET_KEY=p_o3vp1rg5)t^lxm9-43%0)s-=1qpeq%o7gfq+e4#*!t+_ev82
32-
set DEBUG=True
33-
set ALLOWED_HOSTS=0.0.0.0,127.0.0.1
34-
set DATABASE_URL=postgres://postgres:your_password@:5432/djangosnippets
35-
set DJANGO_SETTINGS_MODULE=djangosnippets.settings.development
36-
set SEARCHBOX_SSL_URL=http://elasticsearch:9200/
37-
set SESSION_COOKIE_SECURE=False
26+
.. code-block:: console
3827
39-
Go back to your terminal. You will need to run the command below whenever you open a new terminal. ::
28+
python -m venv venv
4029
41-
$ env.bat
30+
Activate in Linux:
4231

43-
Your environment variables are now set and you can proceed with the instructions below.
32+
.. code-block:: console
4433
45-
Development Setup
46-
-----------------
34+
source venv/bin/activate
4735
48-
In a Python 3.11 virtual environment::
36+
Activate in Windows:
4937

50-
$ cd requirements
51-
$ pip install -r development.txt
52-
$ cd ..
53-
$ python manage.py tailwind install
54-
$ python manage.py migrate
38+
.. code-block:: console
5539
56-
Now you can start the development server::
40+
venv\Scripts\activate
5741
58-
$ python manage.py runserver
42+
3. Connect to PostgreSQL
5943

60-
Before you can actually use the site, you have to define at least one
61-
language. If you just want to use the ones from djangosnippets.org, they
62-
are included in the fixtures folder. Also included are five snippets to get you started::
44+
Connect in Linux:
6345

64-
$ python manage.py createsuperuser
65-
$ python manage.py loaddata fixtures/cab.json
46+
.. code-block:: console
6647
67-
To use Tailwind, you need to start the Tailwind server::
48+
psql -U $(whoami) -d postgres
6849
69-
$ python manage.py tailwind start
50+
Connect in Windows:
7051

71-
Now you should be able to use the development version of djangosnippets
72-
on port 8000.
52+
.. code-block:: console
7353
74-
To run tests::
54+
psql -U postgres
7555
76-
$ python manage.py test --settings=djangosnippets.settings.testing
56+
4. Create a PostgreSQL database and role:
57+
58+
.. code-block:: console
59+
60+
postgres=# CREATE DATABASE djangosnippets;
61+
postgres=# CREATE USER djangosnippets WITH SUPERUSER PASSWORD 'djangosnippets';
62+
postgres=# GRANT ALL PRIVILEGES ON DATABASE djangosnippets TO djangosnippets;
63+
64+
Exit psql shell:
65+
66+
.. code-block:: console
67+
68+
postgres=# exit
69+
70+
5. Install requirements:
71+
72+
.. code-block:: console
73+
74+
pip install -r requirements/development.txt
75+
76+
6. Copy `.env.template.local` file, rename to `.env` and configure variables for your local postgres database.
77+
78+
Copy in Linux:
79+
80+
.. code-block:: console
81+
82+
cp .env.template.local .env
83+
84+
Copy in Windows:
85+
86+
.. code-block:: console
87+
88+
copy .env.template.local .env
89+
90+
7. Run migrations and create superuser:
91+
92+
Migrate:
93+
94+
.. code-block:: console
95+
96+
python manage.py migrate
97+
98+
Optionally load data first:
99+
100+
.. code-block:: console
101+
102+
python manage.py loaddata fixtures/cab.json
103+
104+
Create superuser:
105+
106+
.. code-block:: console
107+
108+
python manage.py createsuperuser
109+
110+
8. Install tailwind (npm is required):
111+
112+
.. code-block:: console
113+
114+
python manage.py tailwind install
115+
116+
9. Run server locally:
117+
118+
.. code-block:: console
119+
120+
python manage.py runserver_plus
121+
122+
10. Run tailwind in another terminal locally:
123+
124+
.. code-block:: console
125+
126+
python manage.py tailwind start
77127
78128
Docker
79-
------
129+
======
80130
You need to copy .env.example to .env and configure to your needs. The example is fine to start with development.
81131

82132
You may wish to use docker locally for production dependency testing and development; here are the setup instructions::
@@ -103,8 +153,14 @@ To run our tests with docker::
103153

104154
$ docker-compose -f docker-compose.yml run web python manage.py test --settings=djangosnippets.settings.testing
105155

156+
Test
157+
======
158+
To run tests::
159+
160+
$ python manage.py test --settings=djangosnippets.settings.testing
161+
106162
Styling Contributor?
107-
--------------------
163+
====================
108164

109165
DjangoSnippets uses the Foundation_ framework as the core of its visual style. To
110166
get this working on your local machine you need compass_ and bower_ to compile
@@ -126,7 +182,7 @@ configuration inside `djangosnippets/static/config.rb` is
126182

127183

128184
Production Setup
129-
----------------
185+
================
130186

131187
The production setup is currently tailored to Heroku and, therefore, mostly
132188
automatic. The difference between these two setups is configured in

djangosnippets/settings/base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import dj_database_url
44
from django.contrib import messages
55
from django.urls import reverse
6+
from dotenv import load_dotenv
7+
8+
load_dotenv()
69

710

811
def user_url(user):

requirements/base.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Markdown==3.4.4
1414
Pillow==9.1.0
1515
Pygments==2.12.0
1616
python-akismet==0.4.2
17+
python-dotenv==1.1.1
1718
requests==2.32.4
1819
six==1.15.0
1920
urllib3==1.26.6

requirements/development.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
-r base.txt
2+
Werkzeug[watchdog]==3.0.6
23
flake8==4.0.1
34
isort==5.8.0
45
pre-commit==2.19.0

0 commit comments

Comments
 (0)