Django 中的循环导入错误仅在我导入 geemap 包时发生

Circular Import error in Django occurs only when i import geemap package

我正在尝试将 geemap 与 django 结合使用来构建用于绘制卫星数据的网络应用程序。我已经在我的 django 项目中安装了 geemap 包。我的项目名称是CustomMaps,目录结构如下。 enter image description here

我的代码 CustomMaps.urls.py 如下


from django.contrib import admin
from django.urls import path
from django.conf.urls import include, url




urlpatterns = [
    path('admin/', admin.site.urls),
    path('plotmap/', include('PlotMap.urls')),
]

我的PlotMap.urls.py代码如下

from django.urls import path
from django.conf.urls import include, url
from .views import hello



urlpatterns = [
    path('hello/', hello, name = 'hello'),
]

而我的PlotMap.views.py如下

from django.http import HttpResponse
from django.shortcuts import render
import geemap as gm
#import pandas as pd

def hello(request):
   map = gm.Map()
   return render(request, "PlotMap/hello.html", { "m" : map})

但是我在 运行 项目

上收到以下错误
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "D:\Internship\Django App\MyProject\lib\site-packages\django\urls\resolvers.py", 
line 604, in url_patterns
    iter(patterns)
TypeError: 'module' object is not iterable

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\HP\AppData\Local\Programs\Python\Python36-32\lib\threading.py", line 916, in _bootstrap_inner
    self.run()
  File "C:\Users\HP\AppData\Local\Programs\Python\Python36-32\lib\threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "D:\Internship\Django App\MyProject\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "D:\Internship\Django App\MyProject\lib\site-packages\django\core\management\commands\runserver.py", line 118, in inner_run
    self.check(display_num_errors=True)
  File "D:\Internship\Django App\MyProject\lib\site-packages\django\core\management\base.py", line 423, in check
    databases=databases,
  File "D:\Internship\Django App\MyProject\lib\site-packages\django\core\checks\registry.py", line 76, in run_checks
    new_errors = check(app_configs=app_configs, databases=databases)
  File "D:\Internship\Django App\MyProject\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
    return check_resolver(resolver)
  File "D:\Internship\Django App\MyProject\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
    return check_method()
  File "D:\Internship\Django App\MyProject\lib\site-packages\django\urls\resolvers.py", 
line 416, in check
    for pattern in self.url_patterns:
  File "D:\Internship\Django App\MyProject\lib\site-packages\django\utils\functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "D:\Internship\Django App\MyProject\lib\site-packages\django\urls\resolvers.py", 
line 611, in url_patterns
    raise ImproperlyConfigured(msg.format(name=self.urlconf_name)) from e
django.core.exceptions.ImproperlyConfigured: The included URLconf 'CustomMaps.urls' does not appear to have any patterns in it. If you see valid patterns in the file then the issue is probably caused by a circular import.

但是,如果我 运行 在更改我的 views.py 后使用相同的代码,如下所示,它工作得很好。

from django.http import HttpResponse
from django.shortcuts import render
#import geemap as gm
#import pandas as pd

def hello(request):
   #map = gm.Map()
   return render(request, "PlotMap/hello.html", { })

我无法理解为什么我的 'import geemap' 会导致 CustomMaps.urls.py 中出现循环导入错误。我尝试搜索相同的内容,但直到现在才找到任何东西。如果有人可以帮助我,那么我很快就能继续我的工作了,谢谢。

实际上,我尝试安装新版本的 python(3.8) 并下载了新版本的 geemap(0.11.4) 解决了问题。

但是,我仍在努力研究如何在我的 django 模板中显示 geemap.Map() 的实例,任何建议都会很有帮助。

我会 post 一个新的问题。 这里:How to display an instance of geemap.Map() in Django Template