如何在管理面板中编辑django task.py代码?

时间:2021-10-10 06:15:57

I have some functions as tasks in my tasks.py file in django and I want to be able to edit the code of each task in my administration panel. Is there any way of doing this. If possible, I would also like to be able to add more tasks in my tasks.py file directly through administration panel without having to go into tasks.py file to add a new task function. If anyone can point me in the right direction, that would be really appreciated.

我在django的tasks.py文件中有一些函数作为任务,我希望能够在我的管理面板中编辑每个任务的代码。有没有办法做到这一点。如果可能的话,我还希望能够通过管理面板直接在tasks.py文件中添加更多任务,而无需进入tasks.py文件来添加新的任务功能。如果有人能指出我正确的方向,那将非常感激。

1 个解决方案

#1


0  

As Peter was saying it is definitely a bad idea. If you must do it, then below one might be little better:

正如彼得所说,这绝对是一个坏主意。如果你必须这样做,那么低于一个可能会好一点:

Create a view to render a form, where user can choose the task name, class name, and then a text area to write his function or task (or) totally new task.py itself (as per your requirement).

创建一个视图来呈现一个表单,用户可以在其中选择任务名称,类名称,然后选择一个文本区域来编写他的函数或任务(或)全新的task.py本身(根据您的要求)。

Once submitted, in the backend check for pep8 code formatting and (having a copy of your entire source code in your server/somewhere) and copy this new file there and run python manage.py shell to just basic sanitize the code.

一旦提交,在后端检查pep8代码格式化和(在你的服务器/某处有你的整个源代码的副本)并在那里复制这个新文件并运行python manage.py shell以基本清理代码。

Restrict the access to this form based on users model (users).

根据用户模型(用户)限制对此表单的访问。

Again as Peter was saying this is totally spectacular security hole.

彼得再次说这是完全壮观的安全漏洞。

#1


0  

As Peter was saying it is definitely a bad idea. If you must do it, then below one might be little better:

正如彼得所说,这绝对是一个坏主意。如果你必须这样做,那么低于一个可能会好一点:

Create a view to render a form, where user can choose the task name, class name, and then a text area to write his function or task (or) totally new task.py itself (as per your requirement).

创建一个视图来呈现一个表单,用户可以在其中选择任务名称,类名称,然后选择一个文本区域来编写他的函数或任务(或)全新的task.py本身(根据您的要求)。

Once submitted, in the backend check for pep8 code formatting and (having a copy of your entire source code in your server/somewhere) and copy this new file there and run python manage.py shell to just basic sanitize the code.

一旦提交,在后端检查pep8代码格式化和(在你的服务器/某处有你的整个源代码的副本)并在那里复制这个新文件并运行python manage.py shell以基本清理代码。

Restrict the access to this form based on users model (users).

根据用户模型(用户)限制对此表单的访问。

Again as Peter was saying this is totally spectacular security hole.

彼得再次说这是完全壮观的安全漏洞。