Login

Integrating Django with ToofPy

Author:
Siddhi
Posted:
July 4, 2007
Language:
Python
Version:
.96
Score:
2 (after 2 ratings)

ToofPy is a python server that supports WSGI so you can integrate Django with it via the WSGI handler.

There is already some default Django integration in the source, but it looked really hacked up with many if hasdjango: lines all over the place and hardcoded URLs.

A really simple solution is to create a Tool for wrapping around Django. That is what the above file does. So I removed most of the hardcoded django lines and created the tool above.

ToofPy dynamically loads tools based on paths on the filesystem, so you'll need to put the file above in the WSGI folder path.

Or, if you want to pre-integrate, import the file in the _initops function of WSGIMainTool just after the code to scan the directory.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# Put the contents below into a file DjangoWsgiWrapper.py and put it in your 
# WSGI Tool directory
# If you want to pre-integrate it (ie not have it picked up from the 
# filesystem), then add "import DjangoWsgiWrapper" to the _initopts function 
# in WSGIMainTool (WSGITool.py)

import os
from django.core.handlers.wsgi import WSGIHandler

# replace with your settings file
os.environ['DJANGO_SETTINGS_MODULE'] = "apps.settings" 

# replace "app" with the name of your app. 
# You will access django by going to http://yoursite/WSGI/app
registerWSGI('app', WSGIHandler()) 

More like this

  1. Template tag - list punctuation for a list of items by shapiromatron 2 months ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 2 months, 1 week ago
  3. Serializer factory with Django Rest Framework by julio 9 months, 1 week ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 9 months, 4 weeks ago
  5. Help text hyperlinks by sa2812 10 months, 3 weeks ago

Comments

Please login first before commenting.