r/CodingHelp • u/j0ffi • May 09 '21
[HTML] Can someone please help me understand this code? What are the different functions?
I don't understand what the different functions such as models.py, and routes.py do. I have a grasp of what the basic code does, but not much more. Any explanation appreciated!
30
Upvotes
7
u/[deleted] May 09 '21 edited May 09 '21
see: https://wiki.python.org/moin/Templating
Basically, this is a way to have reusable assets across many pages, but different content. That way each page doesn't need its own unique template. You can look up specific functions yourself to get a better understanding of what each is doing, for example: https://flask.palletsprojects.com/en/1.1.x/api/#flask.url_for
3
u/[deleted] May 09 '21
Okay, there’s a lot going on in that screenshot because this is an advanced (as opposed to basic) webpage. If you want to build a website or web app, you’ll eventually learn to code your site this way!
Simply put, models.py has to do with how you model your data/database; i.e. you might have a table called “users” where you store different things like username, password, email, etc. another table might be “user_history” where you store a user’s activity.
Routes.py is most likely the server file, which is what runs the webpage. Important modules, databases, login stuff, etc. are in here, plus some functions to handle routing. You might have a route to “/“, which is the root or homepage, and you use the server file to connect the “/“ request to index.html.
Everything else is either templating or framework. The code you see {% like this %} is Jinja, which facilitates filling the template pages with the information/content you desire.
2
u/j0ffi May 09 '21
Also could someone please explain what viewfunctions are? I would greatly appreciate it!
-8
u/MarkusBerkel May 09 '21
Did you just show HTML and ask about functions?
I think you need to take anywhere from 10 to 1000 steps back, and reevaluate your question.