Although setting up a new Django/Python website requires a few steps, it is easy to get up and running!
The first steps are below. After that, you might want to see about putting your project on github, or gitlab, and setting up Apache on Ubuntu to serve your site.
- Create initial folder.
- Create virtual environment.
- Install Django.
- Create project.
- Couple little modifications to skeleton files.
- Run manage.py commands.
- Initialize Git
- That’s It!
Create Initial Folder
First, create the root folder for your project. Something like ~/projects/demo1
$ mkdir demo1
Create Virtual Environment
$ cd demo1
$ python -m venv venv
$ . venv/bin/activate
Depending on your platform, this may not work. The bin may be placed in a scripts folder, so …
$ . venv/scripts/activate
$ pip install django
$ django-admin startproject demo1
Couple little modifications to skeleton files
To Template>Options in settings.py
At the bottom of settings.py
STATIC_URL = '/static/'
STATIC_ROOT = 'static/' # os.path.join(BASE_DIR, STATIC_URL)
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
Run manage.py commands
$ python manage.py makemigrations
$ python manage.py collectstatic
$ python manage.py migrate
$ python manage.py createsuperuser
Before initializing git, we first need to add a .gitignore file, a .gitattributes file, and a README.md file.
$ git init
$ git add .
$ git commit -m "initial commit"
That’s it, you’re done. You are now ready to look at your site at http://127.0.0.1:8000 by running:
$ python manage.py runserver 127.0.0.1:8000
Now you can work on your project. Don’t forget to commit your changes. You should setup a repo on github, or gitlab to host your project.
You may also want to look into hosting your site. Setting up Apache on Ubuntu is a recommended way to serve your site.