May-02-2020, 09:28 AM
Good morning lads, and gents.
I'm currently trying to dig into Flask, and create a simple webpage with it.
For better learning, I also have a project beside of that, where I can use the learned things.
There 2 different problems I have:
1.
Right now I really do not know how to structure the code ?
The tutorial I follow is as follows:
Github: https://github.com/CoreyMSchafer/code_sn...Flask_Blog
Youtube:
Here's the structure:
run.py
-flaskblog
|- static
- main.css
|- templates
- about.html
- login. html etc.
__init__.py
forms.py
models.py
routes.py
site.db
Now I've the webpage. So far so good. Nothing tooo brainbreaking.
Now I want to add an existing project/idea, but I dotn rteally know where to add the code ?
My plan is to login to a specific website, scrape all needed data, store it into the db, and output it on the webpage.
Storage, and output are no problem. The Tutorial mentioned that pretty well.
But where can/should i put the code for the login, and data scrape ?
Should I simply add a folder
|- src ,
and put all necessary code in it ?
2.
How do i start the project then ?
I want to create a button on the website " start " and " stop ". Each of it sets a flag in my db, if the webpage should be scraped or not.
The frontend will be started as follows:
Theoretically, I would just add the task handler to __init__ like,
Would that be a good way ?
I'm really thankful for any kind of help, so I can understand such projects structure, better ...
Kr
I'm currently trying to dig into Flask, and create a simple webpage with it.
For better learning, I also have a project beside of that, where I can use the learned things.
There 2 different problems I have:
1.
Right now I really do not know how to structure the code ?
The tutorial I follow is as follows:
Github: https://github.com/CoreyMSchafer/code_sn...Flask_Blog
Youtube:
Here's the structure:
run.py
-flaskblog
|- static
- main.css
|- templates
- about.html
- login. html etc.
__init__.py
forms.py
models.py
routes.py
site.db
Now I've the webpage. So far so good. Nothing tooo brainbreaking.
Now I want to add an existing project/idea, but I dotn rteally know where to add the code ?
My plan is to login to a specific website, scrape all needed data, store it into the db, and output it on the webpage.
Storage, and output are no problem. The Tutorial mentioned that pretty well.
But where can/should i put the code for the login, and data scrape ?
Should I simply add a folder
|- src ,
and put all necessary code in it ?
2.
How do i start the project then ?
I want to create a button on the website " start " and " stop ". Each of it sets a flag in my db, if the webpage should be scraped or not.
The frontend will be started as follows:
1 2 3 4 5 6 7 |
[u]run.py[ / u] from flaskblog import app # to run flask webserver directly without settings env vars if __name__ = = '__main__' : app.run(debug = True ) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
[u]__init__.py[ / u] from flask import Flask from flask_sqlalchemy import SQLAlchemy from flask_bcrypt import Bcrypt # INIT app = Flask(__name__) app.config[ 'SECRET_KEY' ] = '336b60648fd3b8dc33732eb21e968777' # DB instance db = SQLAlchemy(app) bcrypt = Bcrypt(app) from flaskblog import routes |
1 2 3 4 |
[u]__init__.py[ / u] from src import TaskHandler data = TaskHandler() |
I'm really thankful for any kind of help, so I can understand such projects structure, better ...
Kr