I have seizures that I want to try new frameworks on a regular basis. Is it light this time? I want to do things, so I'm just getting started with Flask in Python. At first I thought I would do it on Ubuntu, but I decided to do it on Windows 10 as the host OS because the disk space reserved for VirtualBox was exhausted. (There are a lot of wasteful hardships by doing it on Windows, but I don't care about that.)
It is best to look at the pdf of the head family. I think it's a little difficult to understand if I have a habit of English (the problem with language ability is the best), but I think it's okay if I pick up and read the commands. PDF of the head family
To be honest, I'm just picking up the above pdf related to Windows, so please forgive me. Start from the situation where Python 3 series is already installed.
> python ez_setup.py
2. Install pip
Then install something called pip.
It's a "Python package management system". If it is Python 3.4 or later, it seems that it is attached by default, so did you need to install it? It's a mystery ...
```> easy_install pip```
3. Install virtualenv
Mysterious tools are coming out one after another. (Because I was away from Python for a while)
Please refer to this article for the explanation.
http://qiita.com/caad1229/items/325ca5c8ad198b0ebce7
Personally, I often try it in the directory c: \ practice \ hoge, so this time it looks like this.
Please read it as good.
#### **`\practice\flask>pip install virtualenv`**
```c
It has nothing to do with the main subject, but I got a message that pip is old, so I updated it according to the message.
Collecting virtualenv Downloading virtualenv-15.1.0-py2.py3-none-any.whl (1.8MB) 100% |################################| 1.8MB 380kB/s Installing collected packages: virtualenv Successfully installed virtualenv-15.1.0 You are using pip version 8.1.1, however version 9.0.1 is available. You should consider upgrading via the 'python -m pip install --upgrade pip' command. C:\practice\flask>python -m pip install --upgrade pip
4. Create a project directory and install Flask
I feel that the granularity of the explanation has become coarse at once, but create a working directory and install Flask as follows.
C:\practice\flask>mkdir myproject C:\practice\flask>cd myproject C:\practice\flask\myproject>virtualenv venv C:\practice\flask\myproject>venv\scripts\activate ↓ This state seems to be the state of virtualenv. On the contrary, when exiting, the command deactivate (venv) C:\practice\flask\myproject>pip install Flask
# Implementation of Hello, world!
Let's implement and run Hello World for the time being.
I wrote the code in C: \ practice \ flask \ myproject with the name hello-flask.py.
The content is almost a complete copy of the original tutorial.
hello-flask.py
#### **`hello-flask.py`**
```py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, Flask World!'
And run.
(venv) C:\practice\flask\myproject>set FLASK_APP=hello-flask.py
(venv) C:\practice\flask\myproject>flask run
* Serving Flask app "hello-flask"
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
with this, http://127.0.0.1:5000/ You can see the greeting from your browser by accessing!
If you feel like it, I think I'll move the gitHub sample and play around with it. On a scale, this [minitwit] seems to be good. https://github.com/pallets/flask/tree/master/examples/minitwit
Recommended Posts