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
First open up the terminal and run the command line to install python3
brew install python
Check the version:
python3
Run the command to install django:
sudo pip install django
Open a terminal and type the following command cd to Desktop: cd Desktop
Create a project django python_web:
django-admin startproject python_web
Then call the directory python_web: cd python_web
Open project with IDE vscode: code.
You can press the “control + ~” combination to open the terminal that is built into the IDE.
Run the project:
python manage.py runserver
Then go to the browser to type http: // localhost: 8000 / or http://127.0.0.1:8000/ to check.
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.
Create a simple webapp:
python manage.py startapp home
After running the command:
Then update the settings.py file : Declare the project that we have just created this app.
Update db:
python manage.py migrate
Web activity:
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
Create a file urls.py in the home directory: touch home / urls.py
Next call urls from the home app in the python_web folder: urls.py
Run the runserver command:
python manage.py runserver
=> Visit http: // localhost: 8000 /
There are 2 urls to choose from: admin / home
Access: This is image title => result:
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