开发者

Django custom management commands from admin interface

开发者 https://www.devze.com 2023-02-01 06:17 出处:网络
I asked a previous question getting a django command to run on a schedule.I got a solution for that question, but I still want to get my commands to run from the admin interface.The obstacle I\'m hitt

I asked a previous question getting a django command to run on a schedule. I got a solution for that question, but I still want to get my commands to run from the admin interface. The obstacle I'm hitting is that my custom management commands aren't getting re开发者_高级运维cognized once I get to the admin interface.

I traced this back to the __init__.py file of the django/core/management utility. There seems to be some strange behavior going on. When the server first comes up, a dictionary variable _commands is populated with the core commands (from django/core/management/commands). Custom management commands from all of the installed apps are also pushed into the _commands variable for an overall dictionary of all management commands.

Somehow, though between when the server starts and when django-chronograph goes to run the job from the admin interface, the _commands variable loses the custom commands; the only commands in the dictionary are the core commands. I'm not sure why this is. Could it be a path issue? Am I missing some setting? Is it a django-chronograph specific problem? So forget scheduling. How might I run a custom management command from the django admin graphical interface to prove that it can indeed be done? Or rather, how can I make sure that custom management commands available from said interface?


I'm also using django-chronograph

and for me it works fine. I did also run once into the problem that my custom commands were not regognized by the auto-discovery feature. I think the first reason was because the custom command had an error in it. Thus it might be an idea to check whether your custom commands run without problems from the command line.

The second reason was indeed some strange path issue. I might check back with my hosting provider to provide you with a solution. Will post back to you in a few days..


i am the "unix-guy" mentioned above by tom tom.

as far as i remember there were some issues in the cronograph code itself, so it would be a good idea to use the code tom tom posted in the comments.

where on the filesystem is django-cronograph stored (in you app-folder, in an extra "lib-folder" or in your site-packages?

when you have it in site-packages or another folder that is in your "global pythonpath" pathing should be no issue.

the cron-process itself DOES NOT USE THE SAME pythonpath, as your django app. remember: you start the cron-process via your crontab - right? so there are 2 different process who do not "know" each other: the cron-process AND the django-process (initialized by the webserver) so i would suggest to call the following script via crontab and export pythonpath again:

#!/bin/bash

PYTHONPATH=/path/to/libs:/path/to/project_root:/path/to/other/libs/used/in/project
export PYTHONPATH

python /path/to/project/manage.py cron

so the cron-started-process has the same pythonpath-information as your project.

greez from vienna/austria

berni

0

精彩评论

暂无评论...
验证码 换一张
取 消