Steps to develop a web application in Python

I decided to make a web application with python and summarized the procedure. I will update it from time to time. (MacOS Sierra ver10.12.4)

Install python (install 2.7 series)

https://www.python.org/downloads/

Install pip (python version control system)

http://uxmilk.jp/12691

Install django (Python web framework)

http://www.sejuku.net/blog/28235

PATH to django-admin.py

http://qiita.com/astronaughts/items/2cc6e8f18290e18a742d

↓ It seems that you are going to see the MacOS standard Python library, so put it in your PATH

sudo ln -s /Library/Frameworks/Python.framework/Versions/2.7/bin/django-admin.py /usr/local/bin/

Permission settings

If you do not do this, you will be asked to enter the password each time you save the py file, or you will not be able to add the file.

sudo chmod +x /usr/local/bin/django-admin.py

** Supplement ** How to open / usr / local / (mac) http://qiita.com/DarkLight_0/items/d257d4b8f27ad670f40d

Make a project

django-admin startproject mySite
python manage.py startapp myapp(Make it with a different name from mySite)

Refer to "Creating a Polls application". .. .. https://docs.djangoproject.com/ja/1.11/intro/tutorial01/

Database connection

Install MySQL on Mac

http://qiita.com/griffin3104/items/c7908359a3e3e18cd269

Connect to MySQL with Python3 + Django

http://qiita.com/aeas44/items/90c867aa2d02f9047ef0

Steps to create a table in MySQL from model creation

Describe the model like this

myapp/models.py


from django.db import models

class Question(models.Model):
    question_text = models.CharField(max_length=200)
    pub_date = models.DateTimeField('date published')

Then execute ↓ Save model changes in migration form (save to file on disk)

python manage.py makemigrations myapp

Check what SQL the migration executes (only if you want to check)

python manage.py sqlmigrate polls 0001

Create a model table in the database

python manage.py migrate

Error resolution memo

SyntaxError: Non-ASCII character '\xe3' It can be fixed by writing "# coding: utf-8" at the beginning of the executable file.

How to find out which port you are using as a LISTEN on your mac

I wanted to find out the port number used by MySQL. .. .. http://qiita.com/yokozawa/items/dbcb3b31f9308e4dcefc

sudo lsof -i -P | grep "LISTEN"

Recommended Posts

Steps to develop a web application in Python
(Python) Try to develop a web application using Django
How to develop in Python
Web application development memo in python
[ES Lab] I tried to develop a WEB application with Python and Flask ②
A standard way to develop and distribute packages in Python
How to develop in a virtual environment of Python [Memo]
Display matplotlib diagrams in a web application
How to get a stacktrace in python
[Python] A quick web application with Bottle!
Run a Python web application with Docker
I wrote a script to extract a web page link in Python
First steps to try Google CloudVision in Python
Try to calculate a statistical problem in Python
How to open a web browser from python
How to clear tuples in a list (Python)
To execute a Python enumerate function in JavaScript
How to embed a variable in a python string
I want to create a window in Python
How to create a JSON file in Python
3 steps to put Python + mecab in yum only
A clever way to time processing in Python
I tried to develop a Formatter that outputs Python logs in JSON
Steps to create a Twitter bot with python
To add a module to python put in Julialang
How to notify a Discord channel in Python
[Python] How to draw a histogram in Matplotlib
A story about everything from data collection to AI development and Web application release in Python (3. AI development)
I want to make a web application using React and Python flask
What I was addicted to when creating a web application in a windows environment
I searched for the skills needed to become a web engineer in Python
Parse a JSON string written to a file in Python
I want to easily implement a timeout in python
Try to make a Python module in C language
I want to write in Python! (2) Let's write a test
Create a plugin to run Python Doctest in Vim (2)
I tried to implement a pseudo pachislot in Python
A memorandum to run a python script in a bat file
Launch a Python web application with Nginx + Gunicorn with Docker
I want to randomly sample a file in Python
Steps from installing Python 3 to creating a Django app
I want to work with a robot in python.
Things to note when initializing a list in Python
Introduction to Linear Algebra in Python: A = LU Decomposition
[Python] Created a method to convert radix in 1 second
Write code to Unit Test a Python web app
How to execute a command using subprocess in Python
Publish / upload a library created in Python to PyPI
Create a function in Python
To flush stdout in Python
Create a dictionary in Python
Web scraping notes in python3
A road to intermediate Python
Login to website in Python
Make a bookmarklet in Python
Speech to speech in python [text to speech]
Web application with Python + Flask ② ③
Draw a heart in Python
Web application with Python + Flask ④
Post to Slack in Python
Let's make a leap in the manufacturing industry by utilizing the Web in addition to Python