florentx / fiole Goto Github PK
View Code? Open in Web Editor NEWThe handy Python web framework
Home Page: https://fiole.readthedocs.org/en/latest/intro.html
License: Other
The handy Python web framework
Home Page: https://fiole.readthedocs.org/en/latest/intro.html
License: Other
When building an API I often need to construct the absolute URL of a resource and then construct new ones using urlparse.urljoin()
. Because of urljoin I need to be sure the URL ends in a trailing /
as otherwise the results are very different. Currently I do this as such:
url = wsgiref.utils.request_uri(request.environ, include_query=False)
if url[-1:] != b'/':
url += b'/'
However I'm rather jealous of the request.path
variable and was wondering if it was possible to add maybe request.url
or request.base_url
or something which is the correct absolute URL with a guaranteed trailing /
?
It is useful to have access to the application object in a view. This can be done in two ways:
environ
: fiole.app
. This is easily done in the .handle_request()
method of Fiole
.If I read correctly the examples, the escape is not by default. I think it's too easy to forget to add |e once. better way would be to add |safe when needed.
It would be nice if parsing of Accept HTTP headers is supported natively. IMHO this is a pretty important function to have when building a REST-like API. The best code I have found for this is from WebOb, and the class is very stand-alone (MIT licensed) so can be easily adopted.
Hi,
Currently you can customise fiole.engine.loader.template_folder
but it is only ever valid as a relative directory to fiole._get_root_folder()
. Instead it would be nice if you could set it to any directory you like similar to how fiole.static_folder
works.
To achieve this I created a subclass of Loader, which does way to much copy-pasting, but shows how I think this should be solved:
class Loader(fiole.Loader):
"""Subclass to control where templates are stored"""
template_folder = os.path.join(fiole._get_root_folder(), 'templates')
def load(self, name, source=None):
"""Return template by name."""
if source is not None:
return (name, unicode(source))
if name in self.templates:
return (name, self.templates[name])
path = os.path.join(self.template_folder, name)
with open(path, 'rb') as f:
return (path, f.read().decode('utf-8'))
This allows you to re-assign Loader.template_folder
to e.g. any absolute directory you like.
Bug is explained in below python code:
import fiole
parent_source = u"""
%def content():
[parent content]
%enddef
{{content()}}
"""
child1_source = u"""
%extends("parent")
%def content():
%if True:
[child 1 content]
%endif
%enddef
"""
child2_source = u"""
%extends("parent")
%def content():
%if True:
[child 2 content]
%endif
%enddef
"""
fiole.get_template("parent", source=parent_source)
# BUG: this prints [parent content] instead [child 1 content]
print fiole.render_template(source=child1_source)
# This prints [child 2 content] as expected
print fiole.render_template(source=child2_source)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.