How to create Django project for beginners


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:

  • conda create --name myEnv django
You can then activate the environment:
  • activate myEnv 
Now, anything installed with pip or conda when this environment is activated, will only be installed for this environment.
You can then deactivate the environment 


  • deactivate myEnv


Or for normal python distributions:
  • pip install django
When you install Django, it actually also installed a command line tool called:
  • django-admin:
  • django-admin startproject first_project

You will then get something that looks like this:


    Screen Shot 2017-01-28 at 12.48.16 AM.png

    • __init__.py
    Screen Shot 2017-01-28 at 12.48.16 AM.png

    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
    This is where you will store all your project settings


      Screen Shot 2017-01-28 at 12.48.16 AM.png


      • urls.py
      This is a Python script that will store all the URL patterns for your project. Basically the different pages of your web application

      ]Screen Shot 2017-01-28 at 12.48.16 AM.png
      • wsgi.py
      This is a Python script that acts as the Web Server Gateway Interface. It will later on help us deploy our web app to production
      Screen Shot 2017-01-28 at 12.48.16 AM.png
      • manage.py
      This is a Python script that we will use a lot. It will be associates with many commands as we build our web app

      Screen Shot 2017-01-28 at 12.48.16 AM.png

      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:

          Django version 1.10.5, using settings 'first_project.settings'
          Starting development server at http://127.0.0.1:8000/
        • Copy and paste that url into your browser
        • You should now see your very first web page being locally hosted on your computer.

      My Instagram

      Made with by Pi-girl | Copyright © 2020 Pi-girl