Overview
- This guide shows how to create a Django project using only a Command Line Interface. No IDE is used.
- Django is Python Web Framework. Though it can also be used to build an API
Prerequisites
- Operating System: Ubuntu 18
- Command Line Interface or Terminal
- Python 3.6 (or above) is installed
- For Ubuntu users refer to this guide.
- Pip and Virtual Env has been installed
- For Ubuntu users refer to this guide.
Steps
01. Navigate or create the project directory
$ cd ~ $ mkdir geek-django-app $ cd geek-django-app
02. Create and activate a virtual environment
$ python3 -m venv venv $ source venv/bin/activate
03. Install Django via Pip
(venv) $ pip install django
It will install Django and other required modules. You can view the other Pip modules it installed, using the `pip freeze`
command, while the Virtual Environment is activated.
(venv) $ pip freeze
04. Create the project using Django. Note that the project name cannot contain dash. Underscore is valid.
(venv) $ django-admin startproject geek_django_main
05. The file structure will look like
geek_django_main/ ├── geek_django_main │ ├── __init__.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py └── manage.py
06. Running the application. Note that the virtual environment should still be activated.
(venv) $ python geek_django_main/manage.py runserver
It will show the following that says that development server is running.
07. On your browser or use curl from a new command line interface session. Visit the following site.
http://127.0.0.1:8000/
Or via CURL on a new session
$ curl http://127.0.0.1:8000
08. On the command line session where Django is running, the access log is visible.