runtime/examples/python/app.py
2020-02-02 22:06:11 +01:00

95 lines
12 KiB
Python

#coding: utf-8
import bottle
content = """
<!DOCTYPE html>
<html>
<head lang="cs">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Roští.cz</title>
<style>
body {
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
color: #2a303c;
background: #54af46;
}
.header {
text-align: center;
}
pre, .row p {
text-align: left;
}
.container {
width: 800px;
margin: 50px auto;
background: #fff;
padding: 20px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
text-align: center;
}
a {
color: #54af46;
}
.project-domain {
color: #54af46;
}
</style>
</head>
<body>
<div class="container">
<div class="header" role="banner">
<a href="https://rosti.cz"><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKkAAABGCAYAAAC3x7R4AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3gsaEh06ilaTpQAAGElJREFUeNrtnXm0HEW9xz/3kgVCEgkhrLJDEpqlOwjIC52QKIwKHuLI+NgUaUBWFXnogI8HARTBkQCCC6sDAhFhdECQwLAF0oQdeljaoLKFCCQBQvbtcu/7o37NrTS9zdybQGB+5+Rkbnd1VVfVt357VUOLWtSi5qhQza3yf4ta9EkFanuhmmtrjcRnm9o/yVwUaAP+uzVNn236xHKpQjU3FugCzgMOAJZW8rXWjLU46SeHk1bytYeBzwFbAIcDexSqObtQzW1TqOb6xXDeFrU46RoHKoVqbmPgdmA3oC8wD5gPvAQ8ANxYydfm6s+0qAXSNQ3WocB0YHhCsanA9yv52ostoLbE/cdBC4VzJtE44MlCNXegcN/WzLZAuuaokq+tAP6Yoeh6wJ2Fas5qAbUF0o+DrmsE14VqblBralsgXdPcdBFwR8bi2wM/anHTFkg/DjoZWJKx7HmFau6QwIBqgbUF0jVh4VPJ194A9gNWZHxscqGa+3uhmtuhN6x9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vVSSVx5DipZ22pmjlriXtEfRfnfFnWq3C7COX4l9x8XzohjFt8MHOvlemljKTNXJvy0UL3zxaE+GHgD+InGvZehNtm1hfyrfyJ6F2xgvFyi6XoB3azpiJeK1V0Q/bpC9zage+X3cuF8B6JyZQ/R2hggi+Ye7dpg0SkDy/1OJBlb+vKKLIaKjNHj4snYWsZzLjDKMYuv9jTa1dJJI65nCe81MvBZQ5nNhhmT6kqrI6quRupPG7MWtehTS/8PMgl14DyUAoIAAAAASUVORK5CYII="></a>
</div>
<div class="row">
<div>
<h2>Kde to jsem?</h2>
<h3 class="project-domain"></h3>
<p>
Na <a href="https://rosti.cz">Roští.cz</a> a prostředí pro vaši aplikaci je připraveno. Nyní můžete obsah adresáře <code>/srv/app</code> vymazat a nahradit ho svoji aplikací. K aplikaci také nezapomeňte nahrát soubor app.py (místo tohoto) a vložit do něj volání své aplikace pro webový server gunicorn.
</p>
<p>
Nejčastěji naši uživatelé používají Django. V takovém případě vypadá soubor <code>app.py</code> takto:
</p>
<pre class="prettyprint">
import os
# Pokud se settings nachází v /srv/app/moje_aplikace,
# bude obsah pro DJANGO_SETTINGS_MODULE: moje_aplikace.settings
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "moje_aplikace.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
</pre>
<p>Příkladem vám může být i aktuální <code>app.py</code>, přes který se vám zobrazila tato stránka. V něm používáme framework bottle.</p>
<p>Pravděpodobně nemáte svou aplikaci bez závislostí, takže během příprav spuštění vaší aplikace nezapomeňte nahrát soubor requirements.txt do adresáře <code>/srv/app/</code>. Po restartu kontejneru proběhne instalace závislostí automaticky.</p>
<p>Do souboru <code>/srv/app/init.sh</code> můžete napsat příkazy, které se mají spustit po každém restart kontejneru. Můžete si tak usnadnit třeba deployment.</p>
</div>
<p>V případě problémů se prosím obraťte na <a href="mailto:podpora@rosti.cz">technickou podporu</a> nebo na <a href="https://docs.rosti.cz/" target="_blank">dokumentaci</a>.</p>
<p>Tým <a href="https://rosti.cz">Roští.cz</a> | <a href="http://twitter.com/rosti_cz">@rosti_cz</a></p>
</div>
</div>
<script type="application/javascript">
var index, len;
var places = document.getElementsByClassName('project-domain');
var domain = document.domain;
for (index = 0, len = places.length; index < len; ++index) {
places[index].innerHTML = domain;
}
</script>
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script>
</body>
</html>
"""
@bottle.route('/')
def home():
return content
application = bottle.default_app()