Writing webapps in python without Django or any structure

I am working on an application that requires a web interface. All I care about is the HTTP interface for iOS, Android Apps to talk to. The backend will use MongoDB.

Do I need to use a Python structure for this? I see that Django wants to create DB interfaces for me. From a quick reading of the Django tutorial, it’s not clear why I should use all of these “applications” into which it is included, for example, admin, auth, etc. I have not seen a way to disable the DB interface in Django.

When I wrote php code earlier, and all I needed was a php apache module, and I got access to the HTTP headers in php code, from where I myself managed. Can't I do something like this using python? Why do people use frameworks?

+3
source share
2 answers

You can try using Flask , a lightweight web infrastructure that helps you make your interface simple. An example of a simple presentation can be found on the framework website:

@app.route('/login', methods=['GET', 'POST'])
def login():
    if request.method == 'POST':
        do_the_login()
    else:
        show_the_login_form()

With Flask, you don’t have an unnecessary module that Django (admin, auth ...) has by default, so you can focus on database management.


If you need an answer that respects your question, yes, you can make a site in Python without a frame. WSGI can help you with this, but it will be more difficult.
+5
source

EDIT:

Good article on Using Django for (mostly) static sites


ORIGINAL:

Django , . , , , , , , , - , .

- WSGI. , HTTP ... . http://wsgi.readthedocs.org/en/latest/frameworks.html


Django . , , , .

INSTALLED_APPS url(r'^admin/'... urls.py. , () , :)
. , . django.contrib.staticfiles.

( ):

from django.http import HttpResponse
import datetime

def current_datetime(request):
    now = datetime.datetime.now()
    html = "<html><body>It is now %s.</body></html>" % now
    return HttpResponse(html)

urls.py URL- :

url(r'^$', 'testapp.views.current_datetime'),  # on domain root
or
url(r'^da-time/?$', 'testapp.views.current_datetime'),  # on domain.com/da-time/

python manage.py runserver .

, ORM, - Django, , , . response_headers = [('Content-type', 'text/plain')], , , . , , , .. .

+3

All Articles