@@ -3,80 +3,130 @@ djangosnippets.org
3
3
4
4
This code is used to power the snippet sharing site, `djangosnippets.org `_
5
5
6
- Database Setup Using Windows
7
- -----------------------------------
6
+ Development Setup
7
+ =================
8
8
9
- Download the latest version of PostgreSQL _. Click on the executable to start the installation setup wizard.
9
+ Prerequisites
10
+ -------------
10
11
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
15
14
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
+ ------------
18
17
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:
21
19
22
- $ CREATE DATABASE djangosnippets;
20
+ .. code-block :: console
23
21
24
- Close SQL Shell (psql).
22
+ https://github.com/django/djangosnippets.org.git
25
23
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:
29
25
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
38
27
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
40
29
41
- $ env.bat
30
+ Activate in Linux:
42
31
43
- Your environment variables are now set and you can proceed with the instructions below.
32
+ .. code-block :: console
44
33
45
- Development Setup
46
- -----------------
34
+ source venv/bin/activate
47
35
48
- In a Python 3.11 virtual environment: :
36
+ Activate in Windows :
49
37
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
55
39
56
- Now you can start the development server::
40
+ venv\Scripts\activate
57
41
58
- $ python manage.py runserver
42
+ 3. Connect to PostgreSQL
59
43
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:
63
45
64
- $ python manage.py createsuperuser
65
- $ python manage.py loaddata fixtures/cab.json
46
+ .. code-block :: console
66
47
67
- To use Tailwind, you need to start the Tailwind server::
48
+ psql -U $(whoami) -d postgres
68
49
69
- $ python manage.py tailwind start
50
+ Connect in Windows:
70
51
71
- Now you should be able to use the development version of djangosnippets
72
- on port 8000.
52
+ .. code-block :: console
73
53
74
- To run tests::
54
+ psql -U postgres
75
55
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
77
127
78
128
Docker
79
- ------
129
+ ======
80
130
You need to copy .env.example to .env and configure to your needs. The example is fine to start with development.
81
131
82
132
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::
103
153
104
154
$ docker-compose -f docker-compose.yml run web python manage.py test --settings=djangosnippets.settings.testing
105
155
156
+ Test
157
+ ======
158
+ To run tests::
159
+
160
+ $ python manage.py test --settings=djangosnippets.settings.testing
161
+
106
162
Styling Contributor?
107
- --------------------
163
+ ====================
108
164
109
165
DjangoSnippets uses the Foundation _ framework as the core of its visual style. To
110
166
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
126
182
127
183
128
184
Production Setup
129
- ----------------
185
+ ================
130
186
131
187
The production setup is currently tailored to Heroku and, therefore, mostly
132
188
automatic. The difference between these two setups is configured in
0 commit comments