Install and create Project Python, using Django on MacOS

Python is a growing programming language and it shows no signs of slowing down over the next few years. Google, Microsoft, and many corporations, IT companies use to operate their service systems.

Course researchers, big data analysts also like to use Python for their work, because it works, no color, learn fast, use it. You will encounter Python in almost every web application, desktop apps, network servers, machine learning, media tool, etc.

In this article, I would like to guide you to install Python, use Django on Mac OS.

Statistical data: 12/2018

install Python, use Django on Mac OS

1. Install Python and django

1.1 Installing python3

First open up the terminal and run the command line to install python3

brew install python

Check the version:

python3

Installing python3

1.2 Install Django

Run the command to install django:

sudo pip install django

2. Create project

Open a terminal and type the following command cd to Desktop: cd Desktop
Create a project django python_web:

django-admin startproject python_web

Create project

Then call the directory python_web: cd python_web
Open project with IDE vscode: code.

This is image title

You can press the “control + ~” combination to open the terminal that is built into the IDE.

Run the project:

python manage.py runserver

This is image title

Then go to the browser to type http: // localhost: 8000 / or http://127.0.0.1:8000/ to check.

This is image title
So you have successfully created a project already.
To change the port you run the virtual server:

python manage.py runserver 8080

And visit http: // localhost: 8080 / to check.

3. Create WebApp

Create a simple webapp:

python manage.py startapp home

After running the command:

Create WebApp

This is image title

Then update the settings.py file : Declare the project that we have just created this app.

Update db:

python manage.py migrate

Web activity:

This is image title

The user machine sends an HTTP Request to the server, the server that analyzes the user’s request sends a Response to the user.

Write the response handler function: home / views.py

This is image title

Create a file urls.py in the home directory: touch home / urls.py

touch home

Next call urls from the home app in the python_web folder: urls.py

web folder

Run the runserver command:

python manage.py runserver 

=> Visit http: // localhost: 8000 /

This is image title

There are 2 urls to choose from: admin / home
Access: This is image title => result:

This is image title

Code has been pushed to github: https://github.com/buitiendo/dobt_python_web
You can download and test it.

My article introduced you how to install and create simple python projects. Good luck!

#python #programming #Django

Install and create Project Python, using Django on MacOS
15.90 GEEK