Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a good way to package django apps?

I have a django project which is installed by customers on their servers. I've got a few more apps which are optional plugins of functionality that can be installed/uninstalled.

I'd like a simple way to package these plugin apps to make the install/uninstall painless. I dont want them to copy the template files to one directory, app to another one, media to a third one and so on. I would prefer that they need not edit settings.py, though its okay if it can't be helped.

The ideal situation would be if they could simply unzip to a location on the python path (maybe a special plugin directory?), and delete it to uninstall. Is there an easy way to package the apps so that they can be installed this way?

like image 783
Siddhi Avatar asked Aug 28 '09 18:08

Siddhi


People also ask

How do I organize my Django apps?

The way I like to organize my Django Project is – Keeps all Django apps in apps folder, static files (scripts, js, CSS) in the static folder, HTML files in templates folder and images and media content in the media folder.

How do you deliver a Django project?

Django works in a way that after running python manage.py runserver the project is accessible at localhost:8000 . But when you deliver the project to the customer you cannot expect them to open command windows every time, then run python manage.py runserver , then open a browser, then type localhost:8000 and etc.

Is GoDaddy good for Django?

Does GoDaddy support Django? Yes, GoDaddy supports websites and applications built using Django. However, the company recommends choosing a VPS hosting plan or a dedicated server plan for these apps. Once you choose a hosting plan, you can use the cPanel control panel to install Python and Django.


2 Answers

I'll skip over discussion of Python packaging (distutils, setuptools, pip, etc), since it sounds like you'd prefer using simple zip files or tarballs. I'll address the "pain points" you mentioned one at a time:

Template files: As long as you have 'django.template.loaders.app_directories.load_template_source' included in the TEMPLATE_LOADERS setting of your projects, you shouldn't have to worry about this one. Each of your apps can have a "templates/" subdirectory, and templates in there will be loaded just as if they were in your project-wide templates directory.

Media files: App media is a pain. For development, you can use a custom serve_media view that operates similarly to the app_directories template loader (looks for media in each app). In production, you have to either copy the files, use symbolic links, or use webserver-level aliases. There are several utility apps out there that try to smooth over this problem; I now use django-staticfiles.

Editing settings.py: No simple way around this one. For its models, template tags, management commands, etc to work, an app has to be listed in INSTALLED_APPS. What you could do is write some custom code in your settings.py that lists the contents of a certain directory and dynamically adds the packages it finds there to INSTALLED_APPS. A little bit dangerous (think carefully about who has permissions to place files in that directory, because they have the keys to your kingdom), and new files there will only be detected on a server reload, but it should work.

I think if you put together those solutions, it's possible to achieve your ideal situation: unzip to install, delete to uninstall.

like image 175
Carl Meyer Avatar answered Nov 13 '22 08:11

Carl Meyer


Editing settings.py: Your plugin can read its settings from its own settings file in its own directory. They'd only need to edit the root settings.py to add/remove the plug-in path from "INSTALLED_APPS".

like image 1
John Mee Avatar answered Nov 13 '22 08:11

John Mee