0

Here"s an Error I have and I can't solve:

Cannot import name "File" from 'uploadapp.models'

The code below makes it better to understand.

Thanks in advance for your help.

from django.db import models
from .models import File

class File(models.Model):
    file = models.FileField(blank=False, null=False)

    def __str__(self):
        return self.file.name
5
  • 1
    Look at the second import of your file. What are you importing exactly? Commented Aug 5, 2019 at 11:15
  • Please update your answer with your code, instead of attaching image. Few issues are it decreases readability, we can't copy paste from image, etc. Commented Aug 5, 2019 at 11:16
  • Welcome to SO! First of all, don't put images of code in your question, just copy&paste your code here, using proper formatting. Please read How to Ask to learn how to. Second: you can't import File inside the file where you define it. Remove the from .models import File. Commented Aug 5, 2019 at 11:16
  • @MilesDavis I am actually using a class named "File" in my models.py. And also trying to important that "File" in my models.py Commented Aug 5, 2019 at 11:19
  • From where do you want to import that ? Commented Aug 5, 2019 at 14:03

1 Answer 1

2

Circular dependency


You're trying to import File from models.py in models.py file.

Reference: http://effbot.org/zone/import-confusion.htm

Sign up to request clarification or add additional context in comments.

Comments

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.