Insert flask page into another without duplicating code?

I have a page (located in / games / compare /) and this is a mini image comparison game. Users are shown two images and asked to choose between them in response to a question. This page can retrieve images from a database, render a template with javascript and css inside and communicate with the database using AJAX.

Now, if I want to insert this game for voting on the main page without duplicating any code? Ideally, I would update the game, and all pages that “show” the game will also reflect the changes.

I get stuck on how to manage assets for the whole site in a consistent and organized way. Some pages have css, javascript, and I also use frameworks like bootstrap and GIS infrastructure.

Would I put the game as a plan? How do I organize assets (Javascript and CSS) so that there is no duplication?

I currently have a page displaying a template (main.html) that extends another (base.html). Base.html includes header.html, nav.html and footer.html with blocks configured for the body and others.

My current approach is to cut everything at the lowest level and put it together at the highest general level, which makes coding very slow. For example, I have this game for voting, and now it is on a page called vote_game.html and it has everything necessary for the game (full html-page, styles and javascript are included). Now, if I want to include this game on another page, for example, the root index, the only solution I know about is to exclude the js style and full html of the page from vote_game.html, leaving only the html needed for the game, When I create index now, I am importing html from vote_game.html, but I will have to import the style and javascript separately. This means that I have to create every page every time, which is twice as much as I have to do.This process also leaves small files everywhere, as I am constantly refactoring, and this makes development a nightmare in books.

, , .

,

: (, ), ( . - , , , , .

" " //, , , .

+5
1

HTML, Jinja {% include %}. , Jinja . {% import "path/to/macros.html" as my_macros %}.

Flask-Assets .

, , . Python, HTML- , , , .

. HTML, , .

+1

All Articles