Django使用Django-batchimport 404错误添加url.py

时间:2021-07-05 18:07:41

I have created a very basic Djangodb where I am trying to do a batch import of several thousand excel files that I have. In the process of researching the best way to database all of these files I found this: https://github.com/pstch/django-batchimport

我创建了一个非常基本的Djangodb,我试图批量导入我拥有的几千个excel文件。在研究数据库所有这些文件的最佳方法的过程中,我发现了这个:https://github.com/pstch/django-batchimport

I have read through the installation documentations, and on the last step of adding the urls to the url.py file I keep getting a 404 error for both my localhost/admin and localhost/batchimport.

我已经阅读了安装文档,并且在将url添加到url.py文件的最后一步中,我的localhost / admin和localhost / batchimport都出现了404错误。

Here is the code for url.py

这是url.py的代码

from django.conf.urls import include, url, patterns
from django.contrib import admin
from batchimport import *
admin.autodiscover()


urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'export.views.home', name='home'),
    # url(r'^blog/', include('blog.urls')),

    (r'^admin/', include(admin.site.urls)), 
    (r'^batchimport', include('batchimport.urls')),
)

and here is my code for urls.py in my batchimport folder.

这是我的batchimport文件夹中urls.py的代码。

from django.conf.urls import *
from views import ImportUploadView, ImportOptionsView, ImportRunView

urlpatterns = patterns('',
                       url(r'^upload/$',
                           ImportUploadView.as_view(),
                           name='batchimport_upload'),
                       url(r'^options/$',
                           ImportOptionsView.as_view(),
                           name='batchimport_options'),
                       url(r'^run/$',
                           ImportRunView.as_view(),
                           name='batchimport_run'), ) 

Here is the output from the error that I am getting:

这是我得到的错误的输出:

ImportError at /admin/ cannot import name related 
Request Method: GET 
Request URL: http://127.0.0.1:8000/admin/ 
Django Version: 1.8
Exception Type: ImportError
Exception Value: cannot import name related 
Exception Location: /Users/USER/Development/ExportOCC/export/batchimport/utils.py
in <module>, line 5 Python
Executable: /Users/USER/anaconda/bin/python Python
Version:    2.7.9

1 个解决方案

#1


The import is not available in Django 1.8. You can give it a try and import related from the original source. Change batchimport/utils.py like:

Django 1.8中没有导入。您可以试一试并从原始来源导入相关内容。更改batchimport / utils.py如:

from django.db.models import get_model
from django.db.models.fields import AutoField, related

If that works, please also notify the author of django-batchimport!

如果有效,请通知django-batchimport的作者!

#1


The import is not available in Django 1.8. You can give it a try and import related from the original source. Change batchimport/utils.py like:

Django 1.8中没有导入。您可以试一试并从原始来源导入相关内容。更改batchimport / utils.py如:

from django.db.models import get_model
from django.db.models.fields import AutoField, related

If that works, please also notify the author of django-batchimport!

如果有效,请通知django-batchimport的作者!