You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
+
Basic Installation
19
+
~~~~~~~~~~~~~~~~~~
21
20
22
-
$ CREATE DATABASE djangosnippets;
21
+
1. Clone the repo:
23
22
24
-
Close SQL Shell (psql).
23
+
.. code-block:: console
25
24
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. ::
25
+
https://github.com/django/djangosnippets.org.git
29
26
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
27
+
2. Create your virtual environment:
38
28
39
-
Go back to your terminal. You will need to run the command below whenever you open a new terminal. ::
29
+
.. code-block:: console
40
30
41
-
$ env.bat
31
+
python -m venv venv
42
32
43
-
Your environment variables are now set and you can proceed with the instructions below.
33
+
Activate in Linux:
44
34
45
-
Development Setup
46
-
-----------------
35
+
.. code-block:: console
47
36
48
-
In a Python 3.11 virtual environment::
37
+
source venv/bin/activate
49
38
50
-
$ cd requirements
51
-
$ pip install -r development.txt
52
-
$ cd ..
53
-
$ python manage.py tailwind install
54
-
$ python manage.py migrate
39
+
Activate in Windows:
55
40
56
-
Now you can start the development server::
41
+
.. code-block:: console
57
42
58
-
$ python manage.py runserver
43
+
venv\Scripts\activate
59
44
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::
45
+
3. Connect to PostgreSQL
63
46
64
-
$ python manage.py createsuperuser
65
-
$ python manage.py loaddata fixtures/cab.json
47
+
Connect in Linux:
66
48
67
-
To use Tailwind, you need to start the Tailwind server::
49
+
.. code-block:: console
68
50
69
-
$ python manage.py tailwind start
51
+
psql -U $(whoami) -d postgres
70
52
71
-
Now you should be able to use the development version of djangosnippets
72
-
on port 8000.
53
+
Connect in Windows:
73
54
74
-
To run tests::
55
+
.. code-block:: console
75
56
76
-
$ python manage.py test --settings=djangosnippets.settings.testing
57
+
psql -U postgres
58
+
59
+
4. Create a PostgreSQL database and role:
60
+
61
+
.. code-block:: console
62
+
63
+
postgres=# CREATE DATABASE djangosnippets;
64
+
postgres=# CREATE USER djangosnippets WITH SUPERUSER PASSWORD 'djangosnippets';
65
+
postgres=# GRANT ALL PRIVILEGES ON DATABASE djangosnippets TO djangosnippets;
66
+
67
+
Exit psql shell:
68
+
69
+
.. code-block:: console
70
+
71
+
postgres=# exit
72
+
73
+
5. Install requirements:
74
+
75
+
.. code-block:: console
76
+
77
+
pip install -r requirements/development.txt
78
+
79
+
6. Copy `.env.template.local` file, rename to `.env` and configure variables for your local postgres database.
80
+
81
+
Copy in Linux:
82
+
83
+
.. code-block:: console
84
+
85
+
cp .env.template.local .env
86
+
87
+
Copy in Windows:
88
+
89
+
.. code-block:: console
90
+
91
+
copy .env.template.local .env
92
+
93
+
7. Run migrations and create superuser:
94
+
95
+
Migrate:
96
+
97
+
.. code-block:: console
98
+
99
+
python manage.py migrate
100
+
101
+
Optionally load data first:
102
+
103
+
.. code-block:: console
104
+
105
+
python manage.py loaddata fixtures/cab.json
106
+
107
+
Create superuser:
108
+
109
+
.. code-block:: console
110
+
111
+
python manage.py createsuperuser
112
+
113
+
8. Install tailwind (npm is required):
114
+
115
+
.. code-block:: console
116
+
117
+
python manage.py tailwind install
118
+
119
+
9. Run server locally:
120
+
121
+
.. code-block:: console
122
+
123
+
python manage.py runserver_plus
124
+
125
+
10. Run tailwind in another terminal locally:
126
+
127
+
.. code-block:: console
128
+
129
+
python manage.py tailwind start
130
+
131
+
With Docker
132
+
~~~~~~~~~~~~~~~~~~~
133
+
134
+
Using `Docker <https://www.docker.com/products/docker-desktop/>`_ allows you to set up the development environment more quickly if Docker is installed 🐳
135
+
136
+
1. Build the Docker images:
137
+
138
+
.. code-block:: console
139
+
140
+
docker compose -f docker-compose.local.yml build
141
+
142
+
2. Start the containers:
143
+
144
+
.. code-block:: console
145
+
146
+
docker compose -f docker-compose.local.yml up -d
147
+
148
+
3. Go to: http://127.0.0.1:8000/ and enjoy 🙌
77
149
78
150
Docker
79
-
------
151
+
======
80
152
You need to copy .env.example to .env and configure to your needs. The example is fine to start with development.
81
153
82
154
You may wish to use docker locally for production dependency testing and development; here are the setup instructions::
0 commit comments