繁体   English   中英

从Django模型执行自定义python脚本

[英]Execute custom python script from Django models

尝试从Django模型执行python脚本,我收到以下错误:

 File "D:\\FL\\Django\\mysite\\uploadfileapp\\models.py", line 23, in get_absolute_url Best_model_forecast_v11.main(user_avatar) NameError: name 'Best_model_forecast_v11' is not defined 

上面的脚本与models.py位于同一应用程序目录中

from django.db import models
from uploadfileapp.Best_model_forecast_v11 import *
# Create your models here.
from django.urls import reverse

class User(models.Model):

    #the variable to take the inputs
    user_name = models.CharField(max_length=100)
    user_avatar = models.FileField()

    # on submit click on the user entry page, it redirects to the url below.
    def get_absolute_url(self):

        Best_model_forecast_v11.main(user_avatar)
        return reverse('uploadfileapp:home')

您错误地导入了文件,请更改:

from uploadfileapp.Best_model_forecast_v11 import *

至;

from uploadfileapp.models.Best_model_forecast_v11 import *

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM