0

Trying to execute a python script from Django models and I receive the following error:

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

The above script is located in same app directory with 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')
3
  • 1
    You're importing everything from Best_model_forecast_v11 into the current namespace. So you probably want to call main(user_avatar) instead. Hard to say without seeing an excerpt of that module though. Whatever the case - this does work. You're just not importing it correctly. Commented Nov 21, 2017 at 1:29
  • Ok. So how should I import it correctly? Thank you. Commented Nov 21, 2017 at 1:43
  • I'm flying blind without seeing the module - but I would assume something like from uploadfileapp import Best_model_forecast_v11 Commented Nov 21, 2017 at 1:44

1 Answer 1

1

you are incorrectly importing the file, change:

from uploadfileapp.Best_model_forecast_v11 import *

to;

from uploadfileapp.models.Best_model_forecast_v11 import *
Sign up to request clarification or add additional context in comments.

1 Comment

I solved it calling as: main("some csv file") instead of Best_model_forecast_v11.main("some csv file"). The only problem I still face is that I have to pass the file location and name in clear into main function. If I try main(models.FileField()), it will not work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.