How to create Django project for beginners
Django
- Django is a free and open source web framework.
- It is used by many sites, including Pinterest, PBS, Instagram, BitBucket, Washington Times, Mozilla, and more!
- Django was created in 2003 when the web developers at the Lawrence Journal-World newspaper started using Python for their development.
- The fact that is originated at a newspaper is important!
- Because the original developers were surrounded by writers, good written documentation is a key part of Django!
- This means you have excellent references to check on the official Django docs!
- When encountering Django tutorials you will often read that you should create a virtual environment or an “venv”
- Let’s talk about what this is and how to use it!
- A virtual environment allows you to have a virtual installation of Python and packages on your computer.
Creating virtualenv:
You can then activate the environment:- conda create --name myEnv django
- activate myEnv
You can then deactivate the environment
- deactivate myEnv
- pip install django
- django-admin:
- django-admin startproject first_project
- __init__.py
This is a blank Python script that due to its special name let’s Python know that this directory can be treated as a package
- settings.py
- urls.py
- wsgi.py
- manage.py
Let’s use manage.py now:
python manage.py runserver
You will see a bunch of stuff but at the bottom you will see something like:
- Copy and paste that url into your browser
- You should now see your very first web page being locally hosted on your computer.
- Django version 1.10.5, using settings 'first_project.settings'
- Starting development server at http://127.0.0.1:8000/