Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
256 views
in Technique[技术] by (71.8m points)

django - Unable identify mistake in URL pattern

I have 3 apps inside django project (leadmanager) leads, frontend, accounts

Everything is working fine if I dont include accounts.urls (from accounts app) in leadmanager.urls but as soon as I include accounts.urls I getting the following error (all of these apps are registered in settings.py):

$ python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:UsersDanial AhmedDesktopLearningdjango-reactvenvlibsite-packagesdjangourls
esolvers.py", line 591, 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:UsersDanial AhmedAppDataLocalProgramsPythonPython36libhreading.py", line 916, in _bootstrap_inner        
    self.run()
File "C:UsersDanial AhmedAppDataLocalProgramsPythonPython36libhreading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
File "C:UsersDanial AhmedDesktopLearningdjango-reactvenvlibsite-packagesdjangoutilsautoreload.py", line 53, in wrapper
    fn(*args, **kwargs)
File "C:UsersDanial AhmedDesktopLearningdjango-reactvenvlibsite-packagesdjangocoremanagementcommands
unserver.py", line 118, in inner_run
    self.check(display_num_errors=True)
File "C:UsersDanial AhmedDesktopLearningdjango-reactvenvlibsite-packagesdjangocoremanagementase.py", line 396, in check
    databases=databases,
File "C:UsersDanial AhmedDesktopLearningdjango-reactvenvlibsite-packagesdjangocorechecks
egistry.py", line 70, 
in run_checks
    new_errors = check(app_configs=app_configs, databases=databases)
File "C:UsersDanial AhmedDesktopLearningdjango-reactvenvlibsite-packagesdjangocorechecksurls.py", line 13, in check_url_config
    return check_resolver(resolver)
File "C:UsersDanial AhmedDesktopLearningdjango-reactvenvlibsite-packagesdjangocorechecksurls.py", line 23, in check_resolver
    return check_method()
File "C:UsersDanial AhmedDesktopLearningdjango-reactvenvlibsite-packagesdjangourls
esolvers.py", line 408, in check
    for pattern in self.url_patterns:
File "C:UsersDanial AhmedDesktopLearningdjango-reactvenvlibsite-packagesdjangoutilsfunctional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
File "C:UsersDanial AhmedDesktopLearningdjango-reactvenvlibsite-packagesdjangourls
esolvers.py", line 598, in url_patterns
    raise ImproperlyConfigured(msg.format(name=self.urlconf_name)) from e
django.core.exceptions.ImproperlyConfigured: The included URLconf 'leadmanager.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.

leadmanager.url (main):

urlpatterns = [
    path('admin/', admin.site.urls),
    path('',include('frontend.urls')),
    path('',include('leads.urls')),
    path('',include('accounts.urls')),
]

lead.urls:

from rest_framework import routers
from .api import LeadViewSet

router = routers.DefaultRouter()
router.register('api/leads', LeadViewSet, 'leads')
app_name = 'leads'
urlpatterns = router.urls

accounts.urls:

from django.urls import path, include
from .api import ReigsterAPI
from knox import views as knox_views

app_name = 'accounts'
urlpatterns = [
  path('api/auth', include('knox.urls')),
  path('api/auth/register', RegisterAPI.as_view()),
]

frontend.urls:

from django.urls import path
from . import views

urlpatterns = [
    path('',views.index),
]
question from:https://stackoverflow.com/questions/65644412/unable-identify-mistake-in-url-pattern

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In .api I was import serializers.py but I had a typing mistake, my file was called serailizers.py, after fixing name of file everything started working!

I just wish that there was someway to detect this syntax errors, because the error I received was not very helpful.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...