setting up github to pull codes from a different computer.
I have been learning flask/ python from this tutorial
http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world
This blog is pretty good and it explain very well. In the first tutorial,
if you notice, he asks us to create a init.py file, a views.py file and a
main run.py file.
root
/microblog
/apps
/__init__.py
views.py
I created the two files. He asks us to create a run.py file and put it in
the root file. then
chmod a+x run.py
./run.py
It says the file does not exist. If I,
python run.py
It says App module not defined. I cannot figure out the problem, I put the
run.py file in all the files, it doesnt not work what so ever.
I will also include the code so that it would be easier to answer instead
of going to the above link
init.py
from flask import Flask
app = Flask(__name__)
from app import views
views.py
from app import app
@app.route('/')
@app.route('/index')
def index():
return 'Hello world'
run.py
#!flask/bin/python
from app import app
app.run(debug = True)
My questions.
Where should I put the run.py file?
2 Why are we creating different files? Why cant all of them be in one full
file?
init.py -->
he is importing flask which is normal. then assigning app = (name). why is
that? Then why is he importing views from apps?
views.py -->
from app import app? is app an existing module here or the one we just
created? what does @app.route('/') or
@app.route('/index')do?
Can some one put the code together and explain it. I am extremely new to
flask and also python to put it right. Well, I know basic python, I want
to learn flask.
No comments:
Post a Comment