I am unable to understand the what purpose does blueprints and namespaces serve in web app.
I read the documentation but cannot figure it out exactly.
It would be really helpful for me if you give a simple explanation with example for each case.
Thanks!
I may still be missing something, but this tutorial seems to clarify the documentation a bit more.
Regarding #code_dredd's comment:
why should anyone choose to use a Blueprint over a Namespace (or viceversa) when both claim to have the same purpose?
Namespaces appear to be intended for organizing REST endpoints within a given API, whereas Blueprints, in this context, appear to be intended for allowing multiple APIs to be mixed and matched with other APIs or non-REST routes on a Flask App, according to Flask's design specification.
As per flask-restplus:
Flask-RESTPlus provides a way to use almost the same pattern as Flask’s blueprint. The main idea is to split your app into reusable namespaces.
from: http://flask-restplus.readthedocs.io/en/stable/scaling.html
namespace is from the Flask-RESTPlus and Blueprint is from flask to organize your app.
the namespaces modules (specific to Flask-RESTPlus) are reusable namespaces designed like you would do with Flask’s Blueprint.
Related
I have developed an API on App Engine using the endpoints-proto-datastore library. At this point I am exploring the use of Swagger to create an Endpoints specification, and am not sure how to proceed. Support for this is indicated in Google's Endpoints docs, but there's not much to get started, particularly for Python.
If possible, I'd like to continue using just the endpoints library and webapp rather than going to Flask which seems like overkill. Any hints for how one might thus proceed?
I'm willing to understand how Flask's internal app pattern works. I'm not talking about blueprints.
Flask is working differently from eg. Django because you can instanciate any number of apps and give them config.
I'm wondering how Flask's handles config. How does it pass this object to all the parts of the app.
I'm wondering about that because I want to refactor the config of my application to follow this pattern, so I need to understand it.
Edit: I don't have any problem with the Config. I'm just trying to replicate the pattern used in Flask.
Thanks,
Alexis.
In Flask app.config is a dictionary. You can put your configuration data there. That's it.
Wherever you import of reference app it will come with it's config attribute which you can access.
I've developed many applications using the MVC pattern in Zend and Symfony. Now that I'm in Pythonland, I find that many frameworks such as Flask, Django and Pyramid use a file called views.py to contain functions which implement the routes. But, these "views" are really controllers in other MVC frameworks I've used before. Why are they called views in Python web frameworks? And, can I change them to controller.py without tearing a hole in the Python universe?
A view, from the django's perspective is what content is presented on a page. And the template is the how it is presented.
A django view is not exactly a controller equivalent. The controller in some of those other frameworks is how the call of a function happens. In django, that is a part of the framework itself.
Technically, there is nothing preventing you from renaming your views into controllers.- The URL routing scheme takes either the function or the string to the function. As long as you can send the appropriate string to the function (or the function itself), you can call your view whatever you want. However, for the reason stated in the paragraph above and for the fact of meeting the expectations of the other people that work on django, you should not really have files called controller.py.
It's just a matter of getting used to. Hang in there for a bit.
Any pointers, advice on implementing a REST API on App Engine with Python? Using webapp for the application itself.
What I currently know is that I can:
hack up my own webapp handlers for handling REST-like URIs, but this seems to lose its elegance for larger amounts of resources. I mean, it's simple when it comes to temperature/atlanta, but not so much* for even a rather simple /users/alice/address/work (though do keep in mind that I'm not saying this after having implemented that, just after spending some time trying to design an appropriate handler, so my perception may be off).
use the REST functionality provided by one of the bigger Python web frameworks out there. I have some unexplainable sympathy towards web2py, but, since it's not used for the project, bundling it with the application just to provide some REST functionality seems.. overkill?
(Huh, looks like I don't like any of these approaches. Tough.)
So here's me asking: what advice, preferably based on experience, would you have for me here? What are my options, is my view of them correct, did I miss something?
Thanks in advance.
I had a similar issue. Wanting to quickly get my DataStore exposed via REST to WebApps.
Found: AppEngine REST Server.
I have only used it lightly so far, but it certainly appears to be very useful with a small amount of work. And it does use webapp as you suggested.
ProtoRPC is bundled with the SDK, and it is robust and actively developed (however experimental). Although I think the source code itself is a little convoluted, the feature-set is pretty complete and it was made by someone with experience in creating this kind of library. It supports transmiting using JSON, ProtocolBuffer and URL-encoded formats.
Also, you can create APIs that work on the server side and client side -- it defines a 'message' protocol with implementations in Python and JavaScript. I used other "RESTful" Python libraries, but no other provided this consistency out of the box.
Here is the project page and here is the mailing list.
Edit: maybe their documentation is lacking some keywords, but just to be clear: one or the purposes of ProtoRPC is to provide a solid foundation to create REST services.
Has anyone any suggestions on how to use internationalization in app engine / webapp / python. I have seen some posts re - django - translation support but i cant seem to find enough info on how to make it work.
What i need is a solution where
browser can detect language
user can override and set
strings in templates and from code can be localized
easy file editing for language support.
I'm new to app engine so need some easy to follow/understand pointers/code assistance
many than
There are several options to consider.
Standard gettext(). See this code example. The code is outdated: there is a standard way to manage cookies and sessions, so it should be rewritten for the real usage.
Sometimes this method fails, see this issue. Usually it's resolved by just reuploading an application, but this is weird.
Use babel. It's pure python, so it can be integrated easily. The drawback is an external dependency, but it's small and good working. Here is an answer with explanations.
Don't do l10n and i18n in the code. My vision is that GAE should be a backend service, serving html just occasionally.
Recently I did the project requiring web UI in several languages. This time I've generated a set of templates in all languages needed by making a 'master' template using _() and gettext() (python module, not django tags), extracting strings and iterating over the languages. A simple template loader checks the current language and loads an appropriate template. The idea is shamelessly stolen from p. 1.
Here I provide some informations about Internationalization and Localization under the Google App Engine framework.
http://eflorent.blogspot.com/2010/08/internationalization-under-google-app.html