I am trying to use geemap in combination with django to build a web app for plotting satellite data. I have installed the geemap package in my django project. My projects name is CustomMaps, and the directory structure is as below. enter image description here
The code for my CustomMaps.urls.py is as below
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')),
]
The code for my PlotMap.urls.py is as follows
from django.urls import path
from django.conf.urls import include, url
from .views import hello
urlpatterns = [
path('hello/', hello, name = 'hello'),
]
And my PlotMap.views.py is as follows
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})
But I am getting the following error on running the project
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.
But if I run same code after changing my views.py like below it works perfectly fine.
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", { })
I am not able to understand why is my 'import geemap' leading to circular import error in CustomMaps.urls.py. I tried searching for the same, but have not been able to find anything till now. If someone can please help me out then i will be able to proceed with my work soon, Thank You.
Actually, I tried installing a new version of python(3.8) and also downloaded a new version of geemap(0.11.4) which solved the issue.
But, I am still struggling on how to display the instance of geemap.Map()
in my django template, any suggestions would be much helpful.
I will post a new question for the same. Here: How to display an instance of geemap.Map() in Django Template