Search code examples
djangoimportadminpylintdjango-import-export

Unable to import 'import_export'


I am developing an app in Django. I have a model named glossary_entry and I want to be able to use the import_export widget for it (see image for example).

import_export widget

So I have read the docs and acted as follows: I have already run

pip install django-import-export

added to settings.py

INSTALLED_APPS = [
'import_export',

run:

pip freeze>requirements.txt

And in my admin.py I have:

from django.contrib import admin
from .models import glossary_entry 

from import_export import resources
from import_export.admin import ImportExportModelAdmin


class glossary_entry_resource(resources.ModelResource):
    class Meta:
        model=glossary_entry

# Register your models here.
admin.site.register(glossary_entry)

The problem is that when I run the server, I get

Connection negated by 127.0.0.1

But even before that, in my VS code editor, i get an error underlined at lines

from import_export import resources
from import_export.admin import ImportExportModelAdmin

which tells:

Unable to import 'import_export'pylint(import-error)

What am I missing?


Solution

  • Try this code

    from django.contrib import admin
    from .models import glossary_entry 
    
    from import_export import resources
    from import_export.admin import ImportExportModelAdmin
    
    class glossary_entryAdmin(ImportExportModelAdmin):   # FOR ADMIN IMPORT EXPORT ONLY 
        pass
    
    
    admin.site.register(glossary_entry, glossary_entryAdmin)   #  FOR ADMIN IMPORT EXPORT ONLY 
    

    And go through docs https://django-import-export.readthedocs.io/en/latest/