I am trying to run a project in Django 2.2 with Debug=True on Ubuntu but I get this error in python manager.py runserver:
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/django/urls/resolvers.py", line 581, in url_patterns
iter(patterns)
TypeError: 'module' object is not iterable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
self.run()
File "/usr/lib/python3.5/threading.py", line 862, in run
self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.5/dist-packages/django/utils/autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/commands/runserver.py", line 117, in inner_run
self.check(display_num_errors=True)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 390, in check
include_deployment_checks=include_deployment_checks,
File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 377, in _run_checks
return checks.run_checks(**kwargs)
File "/usr/local/lib/python3.5/dist-packages/django/core/checks/registry.py", line 72, in run_checks
new_errors = check(app_configs=app_configs)
File "/usr/local/lib/python3.5/dist-packages/django/core/checks/urls.py", line 40, in check_url_namespaces_unique
all_namespaces = _load_all_namespaces(resolver)
File "/usr/local/lib/python3.5/dist-packages/django/core/checks/urls.py", line 57, in _load_all_namespaces
url_patterns = getattr(resolver, 'url_patterns', [])
File "/usr/local/lib/python3.5/dist-packages/django/utils/functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python3.5/dist-packages/django/urls/resolvers.py", line 588, in url_patterns
raise ImproperlyConfigured(msg.format(name=self.urlconf_name))
django.core.exceptions.ImproperlyConfigured: The included URLconf 'moeaforhdl.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.
This is /myparentapp/urls.py:
from django.conf.urls import include, url
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
url(r'', include('moeaforhdlweb.urls')),
url(r'^admin/', admin.site.urls),
url(r'^tinymce/', include('tinymce.urls'))
]
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
This is /mychildapp/urls.py:
from django.conf.urls import url
from . import views
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^help/$', views.help, name='help')
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
I test this project on Windows 10 and it works perfectly, but not on Ubuntu.
Besides, if I comment this line:
url(r'', include('moeaforhdlweb.urls'))
it works.
Any help will be grateful, thanks a lot.
Related
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:\Users\Danial Ahmed\Desktop\Learning\django-react\venv\lib\site-packages\django\urls\resolvers.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:\Users\Danial Ahmed\AppData\Local\Programs\Python\Python36\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "C:\Users\Danial Ahmed\AppData\Local\Programs\Python\Python36\lib\threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\Danial Ahmed\Desktop\Learning\django-react\venv\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\Danial Ahmed\Desktop\Learning\django-react\venv\lib\site-packages\django\core\management\commands\runserver.py", line 118, in inner_run
self.check(display_num_errors=True)
File "C:\Users\Danial Ahmed\Desktop\Learning\django-react\venv\lib\site-packages\django\core\management\base.py", line 396, in check
databases=databases,
File "C:\Users\Danial Ahmed\Desktop\Learning\django-react\venv\lib\site-packages\django\core\checks\registry.py", line 70,
in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "C:\Users\Danial Ahmed\Desktop\Learning\django-react\venv\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "C:\Users\Danial Ahmed\Desktop\Learning\django-react\venv\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
return check_method()
File "C:\Users\Danial Ahmed\Desktop\Learning\django-react\venv\lib\site-packages\django\urls\resolvers.py", line 408, in check
for pattern in self.url_patterns:
File "C:\Users\Danial Ahmed\Desktop\Learning\django-react\venv\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\Danial Ahmed\Desktop\Learning\django-react\venv\lib\site-packages\django\urls\resolvers.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),
]
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.
Hi could anyone help me fix 'ImportError: cannot import name url' problem?
I have followed tutorial here https://docs.djangoproject.com/en/1.9/intro/tutorial01/
I have tried another tutorial https://docs.djangoproject.com/zh-hans/2.0/ref/urls/#django.urls.include
but neither of them worked
My Django version is 1.11.20
Performing system checks...
Unhandled exception in thread started by Traceback
(most recent call last):
File
"/usr/local/lib/python2.7/dist-packages/django/utils/autoreload.py",
line 228, in wrapper fn(*args, **kwargs)
File
"/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py",
line 124, in inner_run self.check(display_num_errors=True)
File
"/usr/local/lib/python2.7/dist-packages/django/core/management/base.py",
line 359, in check
include_deployment_checks=include_deployment_checks,
File
"/usr/local/lib/python2.7/dist-packages/django/core/management/base.py",
line 346, in _run_checks return
checks.run_checks(**kwargs)
File
"/usr/local/lib/python2.7/dist-packages/django/core/checks/registry.py",
line 81, in run_checks new_errors =
check(app_configs=app_configs)
File
"/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py",
line 16, in check_url_config return
check_resolver(resolver)
File
"/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py",
line 26, in check_resolver return check_method()
File
"/usr/local/lib/python2.7/dist-packages/django/urls/resolvers.py",
line 256, in check for pattern in
self.url_patterns:
File
"/usr/local/lib/python2.7/dist-packages/django/utils/functional.py",
line 35, in get res =
instance.dict[self.name] = self.func(instance)
File
"/usr/local/lib/python2.7/dist-packages/django/urls/resolvers.py",
line 407, in url_patterns patterns =
getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File
"/usr/local/lib/python2.7/dist-packages/django/utils/functional.py",
line 35, in get res =
instance.dict[self.name] = self.func(instance)
File
"/usr/local/lib/python2.7/dist-packages/django/urls/resolvers.py",
line 400, in urlconf_module return
import_module(self.urlconf_name)
File "/usr/lib/python2.7/importlib/init.py", line 37, in
import_module
import(name) File "/home/adduser/cantera_correction/mysite/urls.py", line 16, in
from
django.conf.urls import include, path
ImportError: cannot import name path
path was introduced in django since Django 2.0. So, if you are using Django 1.11, then you can't use it. You need to define urls like this:
from django.conf.urls import url, include
urlpatterns = [
# rest of the urls
url(r'^$', HomeView.as_view()),
]
correct your imports to this:
from django.urls import path, include
This code will work for you.
from django.urls import path
from django.contrib import admin
urlpatterns = [
path('admin/', admin.site.urls),
]
I want to add a new app in the https://github.com/edx/edx-platform.
I am following this https://docs.djangoproject.com/en/2.2/intro/tutorial01/ document
/edx/app/edxapp/edx-platform/myapp/url.py
from django.conf.urls import url
from . import views
urlpatterns = [
url('', views.hello, name = 'hello'),
]
/edx/app/edxapp/edx-platform/lms/envs/common.py
INSTALLED_APPS = [
# Standard ones that are always installed...
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.humanize',
'django.contrib.messages',
'django.contrib.redirects',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.staticfiles',
'djcelery',
'myapp',
.............
/edx/app/edxapp/edx-platform/lms/urls.py
urlpatterns = [
url(r'^$', branding_views.index, name='root'), # Main marketing page, or redirect to courseware
url(r'', include('student.urls')),
# TODO: Move lms specific student views out of common code
url(r'^dashboard/?$', student_views.student_dashboard, name='dashboard'),
url(r'^change_enrollment$', student_views.change_enrollment, name='change_enrollment'),
url(r'^myapp/', include('myapp.urls')),
My Error
Traceback (most recent call last):
File "manage.py", line 123, in <module>
execute_from_command_line([sys.argv[0]] + django_args)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/management/base.py", line 327, in execute
self.check()
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/management/base.py", line 359, in check
include_deployment_checks=include_deployment_checks,
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/management/base.py", line 346, in _run_checks
return checks.run_checks(**kwargs)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/checks/registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/checks/urls.py", line 16, in check_url_config
return check_resolver(resolver)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/checks/urls.py", line 26, in check_resolver
return check_method()
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/urls/resolvers.py", line 256, in check
for pattern in self.url_patterns:
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/urls/resolvers.py", line 407, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/urls/resolvers.py", line 400, in urlconf_module
return import_module(self.urlconf_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/edx/app/edxapp/edx-platform/lms/urls.py", line 6, in <module>
from django.conf.urls import include, url, path
ImportError: cannot import name path
Where I am going wrong. please let me know.
File "/edx/app/edxapp/edx-platform/lms/urls.py", line 6, in <module>
from django.conf.urls import include, url, path
ImportError: cannot import name path
The above error is saying that you can't import path from django.conf.urls. It seems you are using older version of django. so, try the following command to install old version.
$ pip install Django==1.11
and go to file /edx/app/edxapp/edx-platform/lms/urls.py and remove path from import. Then it looks like below.
from django.conf.urls import include, url
i'm learning some things about Django 1.9 and i want to make a login form but with class-based views.
This is mi view code:
from django.shortcuts import render
from django.contrib.auth.views import LoginView
class AlumnoLoginView(LoginView):
template_name = "alumno/login.html"
redirect_authenticated_user = True
And this is my urls code:
from django.conf.urls import url, include
from .views import AlumnoLoginView
app_name = 'alumno'
urlpatterns = [
url(r'^login/$', AlumnoLoginView.as_view(), name="login"),
]
This make an error:
ImportError: cannot import name LoginView
But if I delete the code inside urls nothing happens.
This is the full error trace (with François change):
Unhandled exception in thread started by <function wrapper at 0x7f044ad8ac08>
Traceback (most recent call last):
File "/home/plafhz/Envs/StudentAdmin/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/home/plafhz/Envs/StudentAdmin/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 116, in inner_run
self.check(display_num_errors=True)
File "/home/plafhz/Envs/StudentAdmin/local/lib/python2.7/site-packages/django/core/management/base.py", line 426, in check
include_deployment_checks=include_deployment_checks,
File "/home/plafhz/Envs/StudentAdmin/local/lib/python2.7/site-packages/django/core/checks/registry.py", line 75, in run_checks
new_errors = check(app_configs=app_configs)
File "/home/plafhz/Envs/StudentAdmin/local/lib/python2.7/site-packages/django/core/checks/urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "/home/plafhz/Envs/StudentAdmin/local/lib/python2.7/site-packages/django/core/checks/urls.py", line 23, in check_resolver
for pattern in resolver.url_patterns:
File "/home/plafhz/Envs/StudentAdmin/local/lib/python2.7/site-packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/plafhz/Envs/StudentAdmin/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 417, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/plafhz/Envs/StudentAdmin/local/lib/python2.7/site-packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/plafhz/Envs/StudentAdmin/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 410, in urlconf_module
return import_module(self.urlconf_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/plafhz/Envs/StudentAdmin/studentadmin/studentadmin/urls.py", line 21, in <module>
url(r'^alumno/', include('alumno.urls')),
File "/home/plafhz/Envs/StudentAdmin/local/lib/python2.7/site-packages/django/conf/urls/__init__.py", line 52, in include
urlconf_module = import_module(urlconf_module)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/plafhz/Envs/StudentAdmin/studentadmin/alumno/urls.py", line 3, in <module>
from alumno.views import AlumnoLoginView
File "/home/plafhz/Envs/StudentAdmin/studentadmin/alumno/views.py", line 3, in <module>
from django.contrib.auth.views import LoginView as BaseLoginView
ImportError: cannot import name LoginView
What is wrong?
How I fix it?
Thank :)
Class-based views LoginView and LogoutView are introduced on Django 1.11 and function-based views 'login' and 'logout' are deprecated since then.
You can use class-based views LoginView and LogoutView like this:
from django.contrib.auth.views import LoginView, LogoutView
urlpatterns = [
url(r'^login/$', LoginView.as_view(template_name='...'), name="login"),
]
There's no view called LoginView in django.contrib.auth.views
I think you need.
from django.contrib.auth.views import login
LoginView only available from Django 1.11
cannot import LoginView?
You must be using lower version of django ..Login view supported only in 1.11 or higher version..
You need to install 1.11 or higher version
pip install django==1.11
I am trying to upgrade my version of Django from 1.4.6 to 1.7, but I get the following error, which I have no idea how to solve:
My tracestack is as follows:
C:\Users\user_name\Desktop\project_name\project_name>python ../manage.py runserver
Traceback (most recent call last):
File "../manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 385, in execute_from_command_line utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 354, in execute django.setup()
File "C:\Python27\lib\site-packages\django\__init__.py", line 21, in setup apps.populate(settings.INSTALLED_APPS)
File "C:\Python27\lib\site-packages\django\apps\registry.py", line 115, in populate app_config.ready()
File "C:\Python27\lib\site-packages\debug_toolbar\apps.py", line 15, in ready dt_settings.patch_all()
File "C:\Python27\lib\site-packages\debug_toolbar\settings.py", line 215, in patch_all patch_root_urlconf()
File "C:\Python27\lib\site-packages\debug_toolbar\settings.py", line 203, in patch_root_urlconf reverse('djdt:render_panel')
File "C:\Python27\lib\site-packages\django\core\urlresolvers.py", line 517, in reverse app_list = resolver.app_dict[ns]
File "C:\Python27\lib\site-packages\django\core\urlresolvers.py", line 329, in app_dict self._populate()
File "C:\Python27\lib\site-packages\django\core\urlresolvers.py", line 269, in _populate for pattern in reversed(self.url_patterns):
File "C:\Python27\lib\site-packages\django\core\urlresolvers.py", line 367, in url_patterns patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Python27\lib\site-packages\django\core\urlresolvers.py", line 361, in urlconf_module self._urlconf_module = import_module(self.urlconf_name)
File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module __import__(name)
File "C:\Users\user_name\Desktop\project_name\project_name\urls.py", line 10, in <module> url(r'', include('project_name.users.urls')),
File "C:\Python27\lib\site-packages\django\conf\urls\__init__.py", line 28, in include urlconf_module = import_module(urlconf_module)
File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module __import__(name)
File "C:\Users\user_name\Desktop\project_name\project_name\users\urls.py", line 9, in <module> urlpatterns = patterns('django.contrib.auth.views', NameError: name 'patterns' is not defined
I am using python 2.7.
I have read the change docs and I have replaced all my url tags so that they are now displayed as: {% url "email_change" %} instead of {% url email_change %}
The final line of above errors is:
File "C:\Users\user_name\Desktop\project_name\project_name\users\urls.py", line 9, in <module> urlpatterns = patterns('django.contrib.auth.views', NameError: name 'patterns' is not defined
The code for this page from the users/urls.py file is:
from django.conf.urls import patterns, include, url
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'', include('project_name.core.urls')),
url(r'', include('project_name.users.urls')),
url(r'', include('project_name.registration.urls')),
(r'^i18n/', include('django.conf.urls.i18n')),
# (r'^pages/', include('django.contrib.flatpages.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^rosetta/', include('rosetta.urls')),
url(r'^contact_us/', 'contact.views.contact_us', name='contact_us'),
(r'^ckeditor/', include('ckeditor.urls')),
)
# enable serving uploaded files in the DEBUG mode
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
I am assuming for the error message that the url tag is now incorrect under the new version of Django.
Can anyone provide some help on how to solve this issue, b/c I am really stuck?
** EDIT - added core urls.py file **
The following code is from my core/urls.py file
from django.conf.urls import patterns, url
urlpatterns = patterns('project_name.core.views',
# ACHIEVEMENT DETAILS.
url(r'^resume_details/achievement_details/$',
'achievement_details',
name='achievement_details'),
url(r'^resume_details/achievement_details/add/$',
'achievement_details_add',
name='achievement_details_add'),
url(
r'^resume_details/achievement_details/delete/(?P<achievement_details_id>\d+)/$',
'achievement_details_delete',
name='achievement_details_delete'),
url(
r'^resume_details/achievement_details/duplicate/(?P<achievement_details_id>\d+)/$',
'achievement_details_duplicate',
name='achievement_details_duplicate'),
url(
r'^resume_details/achievement_details/edit/(?P<achievement_details_id>\d+)/$',
'achievement_details_edit',
name='achievement_details_edit'),
....
I never did solve this issue.
Instead of upgrading straight from Django 1.4 to 1.7, my advice is to handle your upgrades incrementally.
For example upgrade 1.4 to 1.5, then 1.6 to 1.6 and then 1.6 to 1.7. Make sure you test your project at each upgrade.
Handling the upgrades this way is much more manageable.
I hope that this helps somone.
Not sure if this helps but I recently wrote an article on how to upgrade from 1.4 to 1.7. Definitely learned a lot of things the hard way.
labs.seedinvest.com/backend/upgrading-from-django-1-4-to-django-1-7/