62 lines
3.1 KiB
Markdown
62 lines
3.1 KiB
Markdown
# djangoTest
|
|
A simple web app to test out the django framework.
|
|
|
|
## Overview (how it works)
|
|
### djangoTest Folder
|
|
Project configuration is stored in the `djangoTest` folder. This includes project wide settings as well as how various django apps should be served to users. The built in admin panel is an example of of one of these apps and is served to users who go to the 'admin/' path on the server.
|
|
|
|
### testapp Folder
|
|
The `testapp` folder contains the main django app in this project. It is served to users who go to the root path on the server (empty '' path).
|
|
|
|
### manage.py
|
|
The `manage.py` file is a python script that was automatically generated by `django-admin startproject` to help manage the newly generated project. It can be used to start a dev server or to create a new django app in the project. For a full list of things it can do run `python3 manage.py help`
|
|
|
|
## How to run the dev server
|
|
### Step 1: Installing dependencies
|
|
Install python 3 and the django module. Python 2 is incompatible and [is no longer receiving security updates](https://www.python.org/doc/sunset-python-2/). You will also need git to fetch this repository.
|
|
|
|
**NOTE**: On some *inferior* linux distros you have to run python with the `python3` command to actually run the modern version of python.
|
|
```
|
|
# For Debian/Ubuntu based systems
|
|
sudo apt install git python3 python3-pip
|
|
pip install --user django
|
|
```
|
|
```
|
|
# For Arch Linux based systems
|
|
sudo pacman -Syu git python python-django
|
|
```
|
|
```
|
|
# For Windows sytems
|
|
winget install python3 git.git
|
|
python -m ensurepip --upgrade
|
|
pip install --user django
|
|
```
|
|
|
|
### Step 2: Fetch the code in this repo
|
|
Simply clone this repo using the git command. This will create a folder named djangoTest in your current directory and download the code from the main branch into it.
|
|
```
|
|
git clone https://git.kealoha.me/lks/djangoTest.git
|
|
cd djangoTest
|
|
```
|
|
**NOTE**: If you want to download new updates to the repo after the initial clone you can use the `git pull` command while in the created folder however it will fail if it detects the pull will overwrite any local changes you have made.
|
|
|
|
### Step 3: Initializing the development DB
|
|
Before we can run the server we need to make sure a database is setup to store everthing we need. Luckily django can do this for us using the automagically generated manage.py script.
|
|
```
|
|
python3 manage.py migrate
|
|
```
|
|
**NOTE**: This command also has to be run every time there is an update to the database schema to migrate the db to the new schema. The runserver command will warn you if it detects unmigrated changes.
|
|
|
|
### Step 3.5: Creating an admin user for the admin portal (optional)
|
|
Again the manage.py script can do this for us.
|
|
```
|
|
python3 manage.py createsuperuser
|
|
```
|
|
|
|
### Step 4: Starting the dev server
|
|
Finally we can start the development server.
|
|
```
|
|
python3 manage.py runserver
|
|
```
|
|
You should then be able to connect to the server at [localhost:8000](http://localhost:8000/) and the admin panel is at [localhost:8000/admin/](http://localhost:8000/admin/). The server will automagically reload if you change any of the source files so you just need to refresh the page in your browser to see your changes.
|