[Django]-Django for a simple web application

5đź‘Ť

âś…

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)
👤PhoebeB

4đź‘Ť

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:

  1. create url definition in urls.py
    to some django view
  2. 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.

👤dzida

1đź‘Ť

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.

👤Mike DeSimone

1đź‘Ť

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.

👤Tom Willis

0đź‘Ť

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.

Leave a comment