Amirhossein Nazari
Amirhossein Nazari

Reputation: 45

Import File in django

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

Upvotes: 0

Views: 678

Answers (1)

Umair Mohammad
Umair Mohammad

Reputation: 4635

Circular dependency


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

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

Upvotes: 2

Related Questions