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

时间:2017-11-21 01:26:34

标签: python django execution

尝试从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')

1 个答案:

答案 0 :(得分:1)

您输入的文件不正确,请更改:

from uploadfileapp.Best_model_forecast_v11 import *

from uploadfileapp.models.Best_model_forecast_v11 import *