The tutorial today will show you how to use the python module named django-import-export for importing and exporting files.
If the Django project is done on a virtual environment, you will need to activate it.
Install the python module using the pip utility:
1 2 3 4 | cd Scripts pip.exe install django-import-export Successfully installed backports.csv-1.0.7 diff-match-patch-20181111 django-import-export-1.2.0 odfpy-1.4.0 tablib-0.13.0 xlrd-1.2.0 xlwt-1.3.0 |
You must add the following to the file settings.py the INSTALLED_APPS area:
1 2 | INSTALLED_APPS = [ 'import_export',] |
This will load the django-import-export python module.
Your application will come with the admin.py file for the admin area.
This is my source code for my application test named mychat:
1 2 3 4 5 6 7 8 9 10 11 | from django.contrib import admin # Register your models here. from import_export.admin import ImportExportModelAdmin from .models import MyChat #admin.site.register(MyChat) @admin.register(MyChat) class ViewAdmin(ImportExportModelAdmin): pass #def __init__(self): # super(ViewAdmin, self).__init__() |
The next step is to run the default localhost server:
1 | >python manage.py runserver |
Here’s the final result of the localhost into my browser page: