|
| 1 | +# BT5110 - Your first Django app |
| 2 | + |
| 3 | +A barebones Django app used for the [BT5110](https://nusmods.com/modules/BT5110/data-management-and-warehousing) module at NUS. Shows how to create a web app that |
| 4 | + |
| 5 | +1. Interacts with a database |
| 6 | +2. Is deployed to the internet (for free!) |
| 7 | + |
| 8 | +This template starter code is heavily based on [Python: Getting Started](https://github.com/heroku/python-getting-started.git). |
| 9 | + |
| 10 | +## Running Locally |
| 11 | + |
| 12 | +Make sure you have [Python 3.9](https://docs.python-guide.org/starting/installation/) and [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) installed. Also make sure you have PostgreSQL running and create a new database for local development. Then run the following in a terminal: |
| 13 | + |
| 14 | +```sh |
| 15 | +$ git clone https://github.com/BT5110/demo.git |
| 16 | +$ cd demo |
| 17 | +``` |
| 18 | + |
| 19 | +This will download the code to your computer. One of the files will be called [`.env-sample`](/.env-sample). Make a new file called `.env` where you copy the contents over, and then you can set the values as you desire (namely, make sure `LOCAL_DB_NAME` and `LOCAL_DB_USER` are correctly configured). |
| 20 | + |
| 21 | +Now run the following to finish the setup: |
| 22 | + |
| 23 | +```sh |
| 24 | +$ python3 -m venv .venv |
| 25 | +$ source .venv/bin/activate |
| 26 | +$ pip install -r requirements.txt |
| 27 | + |
| 28 | +$ python manage.py migrate |
| 29 | +$ python manage.py collectstatic |
| 30 | +$ python manage.py runserver |
| 31 | +``` |
| 32 | + |
| 33 | +Your app should now be running on [localhost:8000](http://localhost:8000/). |
| 34 | + |
| 35 | +## Deploying to Heroku |
| 36 | + |
| 37 | +Make sure you have followed the steps above to run it locally. Then: |
| 38 | + |
| 39 | +1. Create a new private repository on GitHub |
| 40 | + * Go to <https://github.com/new>. |
| 41 | + * Name your repository whatever you like. **NB**: Make sure to choose "Private" - this is a requirement to avoid that other students plagiarise your code for the assignment. Also make sure to **not** check any of the boxes under "Initialize this repository with". When you are done, click *Create repository*. |
| 42 | +  |
| 43 | + * Copy the commands under *"...or push an existing repository from the command line"* to push the code you cloned for running locally. |
| 44 | +  |
| 45 | +2. Create the deployment on Heroku |
| 46 | + * Go to <https://dashboard.heroku.com/new-app> and click *Create new app* |
| 47 | +  |
| 48 | + * Name your app whatever you like. For region, Heroku sadly doesn't support Asia. You can choose either Europe or United States. Click *Create app*. |
| 49 | + * Go to *Resources*, Under *Add-ons* search for "postgres" and select it as shown here (you might need to click "Submit Order Form", just make sure you choose the free hobby dev): |
| 50 | +  |
| 51 | + * Go to "Deploy", choose GitHub, connect your GitHub account, search for the repo you created previously to connect to, click "Connect". |
| 52 | +  |
| 53 | + * Deploy your app in its current state, and do such that Heroku automatically deploys changes whenever you push your code to GitHub. |
| 54 | +  |
| 55 | +3. After 1-2 min, you should be able to see your page at `your-app-name.herokuapp.com`! |
| 56 | + |
| 57 | + |
0 commit comments