-
-
Save vulcan25/0e242c63afb9539e98869ad0f77974ab to your computer and use it in GitHub Desktop.
Flask tiny project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, render_template | |
# Because gists don't support subfolders, we pass the `template_folder` argument | |
# to `Flask` to set it as the current directory. If you wish you can create a | |
# subfolder called `templates/` in the project, moving the HTML files there, then | |
# remove that argument from the next line. | |
app = Flask(__name__, template_folder='.') | |
@app.route("/") | |
def index(): | |
""" Just the homepage """ | |
return render_template('index.html') | |
@app.route("/section/<section>") | |
def sections(section): | |
# Mock some logic here depending on the `section` wwhich is passed, | |
# return a different set of products to the frontend. | |
if section == '2': | |
products = [{ 'title': 'Phone', | |
'price': '$899.29', | |
'description': 'A good anroid smartphone.' | |
}] | |
else: | |
products = [] | |
return render_template("sections.html", products = products) | |
@app.context_processor | |
def processor(): | |
""" This function injects vars into every page """ | |
sections = {'mobilni-telefony': "Mobilní telefony", | |
2: "Vertikutátory", | |
3: "Hudební nástroje", | |
} | |
return dict(SITE_TITLE='My Site', | |
SECTIONS=sections) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | |
<meta name="description" content=""> | |
<meta name="author" content=""> | |
<title>Shop Homepage - Start Bootstrap Template</title> | |
<!-- Bootstrap core CSS --> | |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha256-L/W5Wfqfa0sdBNIKN9cG6QA5F2qx4qICmU2VgLruv9Y=" crossorigin="anonymous" /> | |
<!-- Custom styles for this template --> | |
<link href="css/shop-homepage.css" rel="stylesheet"> | |
<style type='text/css'> | |
body { | |
padding-top: 56px; | |
} | |
</style> | |
</head> | |
<body> | |
<!-- Navigation --> | |
<nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top"> | |
<div class="container"> | |
<a class="navbar-brand" href="{{ url_for('index') }}">{{SITE_TITLE}}</a> | |
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation"> | |
<span class="navbar-toggler-icon"></span> | |
</button> | |
<div class="collapse navbar-collapse" id="navbarResponsive"> | |
<ul class="navbar-nav ml-auto"> | |
<li class="nav-item active"> | |
<a class="nav-link" href="#">Home | |
<span class="sr-only">(current)</span> | |
</a> | |
</li> | |
<li class="nav-item"> | |
<a class="nav-link" href="#">About</a> | |
</li> | |
<li class="nav-item"> | |
<a class="nav-link" href="#">Services</a> | |
</li> | |
<li class="nav-item"> | |
<a class="nav-link" href="#">Contact</a> | |
</li> | |
</ul> | |
</div> | |
</div> | |
</nav> | |
<!-- Page Content --> | |
<div class="container"> | |
<div class="row"> | |
<div class="col-lg-3"> | |
<h1 class="my-4">Sections</h1> | |
<div class="list-group"> | |
{% for key, value in SECTIONS.items() %} | |
<a href="{{url_for('sections', section=key)}}" class="list-group-item">{{value}}</a> | |
{% endfor %} | |
</div> | |
</div> | |
<!-- /.col-lg-3 --> | |
{% block content %} | |
{% endblock %} | |
</div> | |
<!-- /.row --> | |
</div> | |
<!-- /.container --> | |
<!-- Footer --> | |
<footer class="py-5 bg-dark"> | |
<div class="container"> | |
<p class="m-0 text-center text-white">Copyright © Your Website 2019</p> | |
</div> | |
<!-- /.container --> | |
</footer> | |
<!-- Bootstrap core JavaScript --> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/js/bootstrap.bundle.min.js" integrity="sha256-fzFFyH01cBVPYzl16KT40wqjhgPtq6FFUB6ckN2+GGw=" crossorigin="anonymous"></script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends 'base.html' %} | |
{% block content %} | |
<div class="col-lg-9"> | |
<div id="carouselExampleIndicators" class="carousel slide my-4" data-ride="carousel"> | |
<ol class="carousel-indicators"> | |
<li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li> | |
<li data-target="#carouselExampleIndicators" data-slide-to="1"></li> | |
<li data-target="#carouselExampleIndicators" data-slide-to="2"></li> | |
</ol> | |
<div class="carousel-inner" role="listbox"> | |
<div class="carousel-item active"> | |
<img class="d-block img-fluid" src="https://i.picsum.photos/id/1060/900/350.jpg" alt="First slide"> | |
</div> | |
<div class="carousel-item"> | |
<img class="d-block img-fluid" src="https://i.picsum.photos/id/79/900/350.jpg" alt="Second slide"> | |
</div> | |
<div class="carousel-item"> | |
<img class="d-block img-fluid" src="https://i.picsum.photos/id/45/900/350.jpg" alt="Third slide"> | |
</div> | |
</div> | |
<a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev"> | |
<span class="carousel-control-prev-icon" aria-hidden="true"></span> | |
<span class="sr-only">Previous</span> | |
</a> | |
<a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next"> | |
<span class="carousel-control-next-icon" aria-hidden="true"></span> | |
<span class="sr-only">Next</span> | |
</a> | |
</div> | |
</div> | |
<!-- /.col-lg-9 --> | |
{% endblock %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends 'base.html' %} | |
{% block content %} | |
<div class="col-lg-9" style='padding-top:20px;'> | |
<div class="row"> | |
{% if products %} | |
{% for product in products %} | |
<div class="col-lg-4 col-md-6 mb-4"> | |
<div class="card h-100"> | |
<a href="#"><img class="card-img-top" src="http://placehold.it/700x400" alt=""></a> | |
<div class="card-body"> | |
<h4 class="card-title"> | |
<a href="#">{{product.title}}</a> | |
</h4> | |
<h5>{{product.price}}</h5> | |
<p class="card-text">{{product.description}}</p> | |
</div> | |
<div class="card-footer"> | |
<small class="text-muted">★ ★ ★ ★ ☆</small> | |
</div> | |
</div> | |
</div> | |
{% endfor %} | |
{% else %} | |
<p>There is nothing here.</p> | |
{% endif %} | |
</div> | |
<!-- /.row --> | |
</div> | |
<!-- /.col-lg-9 --> | |
{% endblock %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment