Last active
August 29, 2015 14:21
-
-
Save ramuta/9cf440ea6605460bee32 to your computer and use it in GitHub Desktop.
Vnos primer
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> | |
<head lang="en"> | |
<meta charset="UTF-8"> | |
<title>SmartNinja basic Jinja template</title> | |
<link rel="stylesheet" href="/assets/css/style.css"> | |
</head> | |
<body> | |
<h1>Hello, SmartNinja!</h1> | |
<form method="post" action="/rezultat"> | |
<input name="vnos"> | |
<button>OK</button> | |
</form> | |
</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
#!/usr/bin/env python | |
import os | |
import jinja2 | |
import webapp2 | |
from models import Sporocilo | |
template_dir = os.path.join(os.path.dirname(__file__), "templates") | |
jinja_env = jinja2.Environment(loader=jinja2.FileSystemLoader(template_dir), autoescape=False) | |
class BaseHandler(webapp2.RequestHandler): | |
def write(self, *a, **kw): | |
self.response.out.write(*a, **kw) | |
def render_str(self, template, **params): | |
t = jinja_env.get_template(template) | |
return t.render(params) | |
def render(self, template, **kw): | |
self.write(self.render_str(template, **kw)) | |
def render_template(self, view_filename, params=None): | |
if not params: | |
params = {} | |
template = jinja_env.get_template(view_filename) | |
self.response.out.write(template.render(params)) | |
class MainHandler(BaseHandler): | |
def get(self): | |
self.render_template("hello.html") | |
class RezultatHandler(BaseHandler): | |
def post(self): | |
rezultat = self.request.get("vnos") | |
sporocilo1 = Sporocilo(vnos=rezultat) | |
sporocilo1.put() | |
self.render_template("rezultat.html") | |
class SeznamHandler(BaseHandler): | |
def get(self): | |
seznam = Sporocilo.query().fetch() | |
params = {"seznam": seznam} | |
self.render_template("seznam.html", params) | |
class PosameznoSporocilo(BaseHandler): | |
def get(self, sporocilo_id): | |
sporocilo = Sporocilo.get_by_id(int(sporocilo_id)) | |
params = {"sporocilo": sporocilo} | |
self.render_template("posamezno_sporocilo.html", params) | |
app = webapp2.WSGIApplication([ | |
webapp2.Route('/', MainHandler), | |
webapp2.Route('/rezultat', RezultatHandler), | |
webapp2.Route('/seznam', SeznamHandler), | |
webapp2.Route('/sporocilo/<sporocilo_id:\d+>', PosameznoSporocilo), | |
], debug=True) |
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 google.appengine.ext import ndb | |
class Sporocilo(ndb.Model): | |
vnos = ndb.StringProperty() | |
created = ndb.DateTimeProperty(auto_now_add=True) |
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> | |
<head lang="en"> | |
<meta charset="UTF-8"> | |
<title>Posamezno sporocilo</title> | |
</head> | |
<body> | |
<h1>Sporocilo</h1> | |
<p>{{ sporocilo.created }}</p> | |
<p>{{ sporocilo.key.id() }}</p> | |
<p>{{ sporocilo.vnos }}</p> | |
</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
<!DOCTYPE html> | |
<html> | |
<head lang="en"> | |
<meta charset="UTF-8"> | |
<title>Rezultat</title> | |
</head> | |
<body> | |
<h1>Hvala za tvojo objavo</h1> | |
</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
<!DOCTYPE html> | |
<html> | |
<head lang="en"> | |
<meta charset="UTF-8"> | |
<title></title> | |
</head> | |
<body> | |
<h1>Seznam sporocil</h1> | |
{% for sporocilo in seznam %} | |
<p><a href="/sporocilo/{{ sporocilo.key.id() }}">{{ sporocilo.vnos }}</a></p> | |
{% endfor %} | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment