I've been tasked with converting a service from Flask to aiohttp. Originally this service used Flask admin, but we are moving away from Flask. I saw that there is a aiohttp-admin package, but frankly, the documentation is very poor to almost non-existent and I can't wrap my head around the examples. Are there any other options for aiohttp admin pages out there? I've been using Jinja2 templates, but I think my solution is lacking.
Which exactly functionality do you lack in aiohttp admin? Please note the demos https://github.com/aio-libs/aiohttp_admin/tree/master/demos, they might contain fully or partially what you're looking for.
If you prefer to use jinja2 templates then aiohttp_admin2 is better for your case. The setup of aiohttp_admin2 is very simple and good cover into the documentation.
from aiohttp import web
from aiohttp_admin2 import setup_admin
app = web.Application()
# setup admin interface
setup_admin(app)
web.run_app(app)
It doesn't cover all flask-admin features, but you can add your own views or automatically generate CRUD views based on sqlAlchemy's models (or mongodb models) without JavaScript code.
This link to the official repository you can find here. Here you can find documentation with demo and examples of code.
Related
I have a fairly large Flask application and I have encountered a need to create view functions in a separate python module. Right now I have all of my view functions in one module where I create my Flask app object, all my view functions, and run the Flask dev server. All of these views so far are urls that users will actually see when using the application so I am okay with keeping these in this existing module. However, I need to have an API where another application will be posting JSON to specific urls. I would like to keep these API handlers (views) separate from the other views.
I have already read the documentation here http://flask.pocoo.org/docs/0.10/patterns/packages/. The way I see it I have two options. I can put my application in a package and create the Flask app in the __init_.py, then import views from each file there as well, with a module to run the app next to the package like it is shown in the docs, or I can create a blueprint for my API handlers and register the blueprint in my existing module.
I am not sure what is the best way to go about this. I am leaning towards blueprints but I need feedback on what other people have done in this situation.
This question is not generally a good question for Stack Overflow, since it appears you're asking for an opinion and your question is vague. You should post code that you've already tried and have a more specific question.
Since you're new, I'll answer as best I can, with the very limited information you posted.
I highly recommend using Blueprints for your situation. It will make it a lot easier in the future to manage the application if it's broken up into modules that are glued together with blueprints. Then you would have a small __ init__.py script, that primarily registers the blueprints.
Where can I find an open source pluggable blog app for Django?
It should support:
RSS/Atom
Comments
the built-in Django authentication system
Markdown (optional)
Akismet or other spam protection (optional)
Plus, I'd like to have to ability to embed the blog front page into another page, maybe in another app.
I'd like it to be as simple as possible - no unneccsary features, and 2-3 apps max.
Thanks.
Check out django packages' grid for blog applications.
I would find find one that looks close to what you are looking for and edit it to fit your needs. That's the great thing about django, the ability to customize.
I've used Django Basic Blog as the base, and customized it to suit my needs, it is part of Django Basic Apps
django-zinnia-blog has RSS feeds, traceback/pingback and comments via django-comments. You can use signals to have your comments checked via akismet. To support markdown you can use a template filter.
Eleven django blog engines you should know
I just started with Google App Engine using python and I was following a tutorial and writing my own little app to get familiar the webapp framework. Now I just noticed the tutorial does the following self.redirect('/'). So that got me wondering: is there a way to redirect to a handler instead of a hardcoded path? Thought that might be better so that you can change your urls without breaking your app.
One alternative would be to have a map of symbolic names to URLs, that way you could redirect to the mapped URL - you could then update your URLs with impunity.
Or if you'd rather just execute the code from another handler, I don't know why you couldn't just make a method call - worst case, you could extract a common method from the two handlers and call that.
This isn't a limitation of App Engine so much as the webapp framework. webapp is intended to be a lightweight framework, providing just the essentials.
If you want fancier redirect behavior, try Django.
The accepted answer made me built my own little router before I realized that in webapp2 you can name your routes and then redirect using that name as described in webapp2 Uri routing
app = webapp2.WSGIApplication(
routes=[webapp2.Route('/', handler='RootController', name='root')])
and then redirect to them in the RequestHandler
self.redirect_to('root')
if your path contains placeholders you can supply the values for the placeholders and the webapp2.Router will build the correct uri for you. Again take a look at webapp2 Uri routing for more detailed information.
I'm developing an app (an API) in python and I would like to offer some of its functionality through a web interface (like web services do).
I've been looking at django, but I don't know if really fits well in my idea. I only want to create a web page that invokes to my API methods in order to acomplish the functionality that offers that web page. But, after followed the tutorial, I feel a little confused about the point of django. It seems to me to be more related with an ORM than a classic web application.
Is django a solution so heavy for such a simple development (as I mentioned, make calls to my API through the web)? Do I always have to use a database?
Thanks.
I love django but there is an lot of it to get your head around! If you don't want the database bit, focus on urls.py and views.py that will process your urls and return the info you want as an http response.
eg. urls.py
urlpatterns += patterns('myapp.views',
url(r'^getstuff/$', 'getstuff' ),
)
in views.py
def getstuff(request):
do whatever in python
return HttpResponse(stuff to return)
You don't need to use database in Django projects.
Basically django comes with some standardized architecture that follows MVC pattern (or MVT as sometimes described). This includes models, views, url dispatching, templates, etc.
Probably you need to do following things to accomplish your task:
create url definition in urls.py
to some django view
write
django view that call somehow your
api and displays result as a web
page
you don't need models and database at all but you need to get familliar with views, urls, templates. It might look like a big machinery for your simple case but if you have some time I encourage you to these django basics.
If you are looking for somethin much simpler I heard about webpy project. This might be better option if you need something really simple.
An important question is: Do you want the web services to be provided by a full-featured server like Apache, or are you just looking at the "web server" to be a thread (or equivalent) in your program?
If you want to run Apache, then I'd recommend something like Werkzeug, which will handle most of the WSGI stuff for you. For templating, I've heard good things about Jinja2.
If that is too much, and all you want is a lightweight, simple server (something that, say, just spits out some HTML or XML when asked, and doesn't need any fancy URL handling), you can use the SimpleHTTPServer or CGIHTTPServer modules that ship with Python.
Django is a full-featured, integrated package that provides almost everything you need to write database-backed web applications. While its various components can be used in isolation, if you're only using one thing (the template and view engines, in your case), it is probably overkill.
No need for a framework at all. Raw wsgi isn't hard but a little verbose. So I like to use WebOb
Here's Raw wsgi
def application(environ, start_response):
start_response("200 OK", [])
return ["<html><body><h1>Hello World</h1></body></html>"]
Here's the webob version
from webob.dec import wsgify
from webob import Request
#wsgify
def application(request):
return Response("<html><body><h1>Hello World</h1></body></html>")
That's enough to run under apache mod_wsgi, and there are plenty of libraries that you can use that expect/produce webob Request and Responses. Anything that Turbogears 2 or repoze.bfg uses is fair game at that point.
You definitely don't have to use a database with Django. Whether it fits your needs, only you can tell. There are other Python web frameworks that you can use.
I'm developing software on google app engine. I'm using the webapp framework. is there any way to avoid hard-coding urls in the html templates? django provides a solution, but I couldn't find one for webapp. thanks in advance..
WebApp is really very basic.
Django url templatetag is closely tied to its idea of URL resolving by matching regex patterns. As WebApp does not have any serious URL resolver, I imagine this would be really hard task to implement something in this line.
But you are not totally out of luck. Werkzeug has very easy to understand yet powerful URL routing mechanism that allows for reversing urls. You can try to base your implementation on this one (or throw away WebApp and use Werkzeug ;), it's really worth a try).
Webapp uses Django templates so:
check out Django templates here
The Django solution is the web app solution.