|
1 | 1 | # Build a Blog Using Django, Vue, and GraphQL |
2 | 2 |
|
3 | | -## Starting the back-end Django application |
4 | | - |
5 | | -In a new terminal tab: |
6 | | - |
7 | | -1. Install the back-end requirements in the environment of your choice: |
8 | | - ```shell |
9 | | - $ cd /path/to/repo/tutorial-drafts/articles/django-vue-graphql/source_code/backend/ |
10 | | - $ python3 -m pip install -r requirements.txt |
11 | | - ``` |
12 | | -1. Create the initial Django database by running migrations: |
13 | | - ```shell |
14 | | - $ python manage.py migrate |
15 | | - ``` |
16 | | -1. Create a Django superuser: |
17 | | - ```shell |
18 | | - $ python manage.py createsuperuser |
19 | | - ``` |
20 | | -1. Run the Django project (by default on port 8000): |
21 | | - ```shell |
22 | | - $ python manage.py runserver |
23 | | - ``` |
24 | | - |
25 | | -## Starting the front-end Vue application |
26 | | - |
27 | | -In a new terminal tab: |
28 | | - |
29 | | -1. Install the front-end requirements: |
30 | | - ```shell |
31 | | - $ cd /path/to/repo/tutorial-drafts/articles/django-vue-graphql/source_code/frontend/ |
32 | | - $ npm install |
33 | | - ``` |
34 | | -1. Run the Vue project (by default on port 8080): |
35 | | - ```shell |
36 | | - $ npm run serve |
37 | | - ``` |
38 | | - |
39 | | -## Add a few posts |
40 | | - |
41 | | -1. Visit [the Django admin](https://localhost:8000/admin) |
42 | | -1. Log in using the superuser you created earlier |
43 | | -1. Write a few posts, adding authors and tags as desired |
44 | | -1. Make sure at least one post is `published` (or no posts will appear) |
45 | | - |
46 | | -## View the blog |
47 | | - |
48 | | -1. Visit [the blog homepage](https://localhost:8080) |
49 | | -1. Browse the posts, tags, and authors |
50 | | - |
51 | | -## Try the GraphQL API yourself |
52 | | - |
53 | | -1. Visit [the GraphiQL interface](https://localhost:8000/graphql) |
54 | | -1. View the *Docs* panel on the top right |
55 | | -1. Create some queries—the available information should auto-populate! |
| 3 | +This repository contains code related to the tutorial on [building a blog using Django, Vue, and GraphQL](https://realpython.com/python-django-blog/). |
| 4 | + |
| 5 | +Navigate to the corresponding folder in this repository to compare your code with the code from the tutorial: |
| 6 | + |
| 7 | +- [Step 1](source_code_step_1/) |
| 8 | +- [Step 2](source_code_step_2/) |
| 9 | +- [Step 3](source_code_step_3/) |
| 10 | +- [Step 4](source_code_step_4/) |
| 11 | +- [Step 5](source_code_step_5/) |
| 12 | +- [Step 6](source_code_step_6/) |
| 13 | +- [Step 7](source_code_step_7/) |
| 14 | +- [Step 8](source_code_step_8/) |
| 15 | +- [Step 9](source_code_final/) |
| 16 | + |
| 17 | +If you want to install the project on your machine without following the tutorial, then you need to follow the steps outlined below. |
| 18 | + |
| 19 | +## Setup |
| 20 | + |
| 21 | +Navigate into the `source_code_final/` folder. In this folder, you'll find the folders `back_end/` and `front_end/`, which represent both projects of the tutorial. |
| 22 | + |
| 23 | +### Back End |
| 24 | + |
| 25 | +Create a new terminal window, navigate into `back_end/`, create, activate a [virtual environment](https://realpython.com/python-virtual-environments-a-primer/), and install the necessary dependencies: |
| 26 | + |
| 27 | +```sh |
| 28 | +$ python -m venv venv |
| 29 | +$ source venv/bin/activate |
| 30 | +(venv) $ python -m pip install -r requirements.txt |
| 31 | +``` |
| 32 | + |
| 33 | +Then, create the initial Django database by running migrations: |
| 34 | + |
| 35 | +```sh |
| 36 | +$ python manage.py migrate |
| 37 | +``` |
| 38 | + |
| 39 | +Create a Django superuser: |
| 40 | + |
| 41 | +```shell |
| 42 | +$ python manage.py createsuperuser |
| 43 | +``` |
| 44 | + |
| 45 | +Run the Django project: |
| 46 | + |
| 47 | +```sh |
| 48 | +$ python manage.py runserver |
| 49 | +``` |
| 50 | + |
| 51 | +Before continuing, it's a good idea to create some users, profiles, and blog posts in the Django admin interface at `http://localhost:8000/admin`. You must use your superuser credentials to log in. |
| 52 | + |
| 53 | +You can visit the GraphiQL platform `http://localhost:8000/graphql` to try out GraphQL queries. |
| 54 | + |
| 55 | +### Front End |
| 56 | + |
| 57 | +Open a new terminal and navigate into `front_end/`. Then, install the front-end requirements: |
| 58 | + |
| 59 | +```sh |
| 60 | +$ npm install --include dev |
| 61 | +``` |
| 62 | + |
| 63 | +Run the Vite development server: |
| 64 | + |
| 65 | +```sh |
| 66 | +$ npm run dev |
| 67 | +``` |
| 68 | + |
| 69 | +You must have the Django development server and the Vite server running at the same time. |
0 commit comments