I'm a beginner in programming and my first project is creating a website using python with django framework as the back-end.However on trying to run the server. I was getting the following error. So can someone please explain?
(myvenv) C:\Users\Rohan Jain\venvi>python manage.py runserver
Performing system checks...
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x000001FACC183378>
Traceback (most recent call last):
File "C:\Users\Rohan Jain\AppData\Local\Programs\Python\Python36\lib\site-packages\django\utils\autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "C:\Users\Rohan Jain\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\commands\runserver.py", line 125, in inner_run
self.check(display_num_errors=True)
File "C:\Users\Rohan Jain\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\base.py", line 359, in check
include_deployment_checks=include_deployment_checks,
File "C:\Users\Rohan Jain\AppData\Local\Programs\Python\Python36\lib\site- packages\django\core\management\base.py", line 346, in _run_checks
return checks.run_checks(**kwargs)
File "C:\Users\Rohan Jain\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\checks\registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\Users\Rohan Jain\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\checks\urls.py", line 16, in check_url_config
return check_resolver(resolver)
File "C:\Users\Rohan Jain\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\checks\urls.py", line 26, in check_resolver
return check_method()
File "C:\Users\Rohan Jain\AppData\Local\Programs\Python\Python36\lib\site-packages\django\urls\resolvers.py", line 254, in check
for pattern in self.url_patterns:
File "C:\Users\Rohan Jain\AppData\Local\Programs\Python\Python36\lib\site-packages\django\utils\functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\Rohan Jain\AppData\Local\Programs\Python\Python36\lib\site-packages\django\urls\resolvers.py", line 405, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Users\Rohan Jain\AppData\Local\Programs\Python\Python36\lib\site-packages\django\utils\functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\Rohan Jain\AppData\Local\Programs\Python\Python36\lib\site-packages\django\urls\resolvers.py", line 398, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Users\Rohan Jain\AppData\Local\Programs\Python\Python36\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
File "C:\Users\Rohan Jain\venvi\mysite\urls.py", line 21, in <module>
url(r'', include('blog.urls')),
NameError: name 'include' is not defined
from django.conf.urls import include, url
^^^^^^^
urlpatterns = [
# ... snip ...
url(r'^community/', include('django_website.aggregator.urls')),
url(r'^contact/', include('django_website.contact.urls')),
# ... snip ...
]
So, for the little explanation:
When you try to run your program, the problem is that the word "include" is not defined anywhere. To solve this situation, you need to define that word and since this is a function from django.conf.urls is as simple as import it at the beginning from your file.
Hope it helps, here is a bit of docs that may help you understand a bit more about django
https://docs.djangoproject.com/en/1.11/topics/http/urls/
Related
I did a pip install -r requirements.txt and after that, realized that my development server could nolonger start. I have been unable to tell which of the files installed caused this. I even tried to re-install a previous requirements.txt file I had before this one but the nothing changed.
Could anyone be having a clue on what exactly is happening from this traceback message?
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Users\Ptar\AppData\Local\Programs\Python\Python39\lib\threading.py", line 973, in _bootstrap_inner
self.run()
File "C:\Users\Ptar\AppData\Local\Programs\Python\Python39\lib\threading.py", line 910, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\Ptar\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "C:\Users\Ptar\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\commands\runserver.py", line 118, in inner_run
self.check(display_num_errors=True)
File "C:\Users\Ptar\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\base.py", line 419, in check
all_issues = checks.run_checks(
File "C:\Users\Ptar\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\checks\registry.py", line 76, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "C:\Users\Ptar\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "C:\Users\Ptar\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
return check_method()
File "C:\Users\Ptar\AppData\Local\Programs\Python\Python39\lib\site-packages\django\urls\resolvers.py", line 412, in check
for pattern in self.url_patterns:
File "C:\Users\Ptar\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\Ptar\AppData\Local\Programs\Python\Python39\lib\site-packages\django\urls\resolvers.py", line 598, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Users\Ptar\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\Ptar\AppData\Local\Programs\Python\Python39\lib\site-packages\django\urls\resolvers.py", line 591, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Users\Ptar\AppData\Local\Programs\Python\Python39\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "D:\Programming\Javascript\React\llr_reacted\llr_django\library\urls.py", line 6, in <module>
from libman import views as core_views
File "D:\Programming\Javascript\React\llr_reacted\llr_django\libman\views.py", line 22, in <module>
from rest_framework.decorators import api_view
File "C:\Users\Ptar\AppData\Local\Programs\Python\Python39\lib\site-packages\rest_framework\decorators.py", line 13, in <module>
from rest_framework.views import APIView
File "C:\Users\Ptar\AppData\Local\Programs\Python\Python39\lib\site-packages\rest_framework\views.py", line 17, in <module>
from rest_framework.schemas import DefaultSchema
File "C:\Users\Ptar\AppData\Local\Programs\Python\Python39\lib\site-packages\rest_framework\schemas\__init__.py", line 33, in <module>
authentication_classes=api_settings.DEFAULT_AUTHENTICATION_CLASSES,
File "C:\Users\Ptar\AppData\Local\Programs\Python\Python39\lib\site-packages\rest_framework\settings.py", line 225, in __getattr__
val = perform_import(val, attr)
File "C:\Users\Ptar\AppData\Local\Programs\Python\Python39\lib\site-packages\rest_framework\settings.py", line 168, in perform_import
return [import_from_string(item, setting_name) for item in val]
File "C:\Users\Ptar\AppData\Local\Programs\Python\Python39\lib\site-packages\rest_framework\settings.py", line 168, in <listcomp>
return [import_from_string(item, setting_name) for item in val]
File "C:\Users\Ptar\AppData\Local\Programs\Python\Python39\lib\site-packages\rest_framework\settings.py", line 177, in import_from_string
return import_string(val)
File "C:\Users\Ptar\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\module_loading.py", line 17, in import_string
module = import_module(module_path)
File "C:\Users\Ptar\AppData\Local\Programs\Python\Python39\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ValueError: source code string cannot contain null bytes
This is what was contained in the requirements.txt that I installed.
asgiref==3.4.1
autopep8==1.6.0
Django==4.0.1
django-cors-headers==3.11.0
djangorestframework==3.13.1
djangorestframework-simplejwt==5.0.0
pycodestyle==2.8.0
PyJWT==2.3.0
pytz==2021.3
sqlparse==0.4.2
toml==0.10.2
tzdata==2021.5
I am facing with the problem of setting the app_name attribute in the included module.
Despite the fact that I have seen similar answers on how to fix it, I did not find something working for me.
Here is my urls.py
from django.conf.urls import url,include
from django.contrib import admin
from intranet import views,forms
from django.contrib.auth import views as auth_views
from django.conf import settings
from rest_framework import routers
from django.conf.urls.static import static
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.urls import reverse
router = routers.DefaultRouter()
router.register(r'pharmakeia', views.PharmakeiaViewSet,base_name='pharmakeia')
router.register(r'doctors', views.DoctorsViewSet,base_name='doctors')
router.register(r'new-pharmakeia', views.VriskoViewSet,base_name='new-pharmakeia')
router.register(r'new-all-pharmakeia', views.VriskoAllViewSet,base_name='new-all-pharmakeia')
views.json_data,base_name='test_pharmakeia')
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^rest/', include(router.urls, namespace='rest')),
url(r'^api-auth/', include(rest_framework.urls, namespace='rest_framework')),
Then I changed the script:
I tried to declare an app_name variable
app_name="intranet"
and then I tried to fix the urls containing the include function
url(r'^rest/', include((router.urls,app_name), namespace='rest')),
url(r'^api-auth/', include(('rest_framework.urls',app_name), namespace='rest_framework')),
I face a new problem
"ModuleNotFoundError: No module named 'router' despite the fact that I have already defined rooter**
Here is my output from command line
self._target(*self._args, **self._kwargs)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/utils/autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run
self.check(display_num_errors=True)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/core/management/base.py", line 390, in check
include_deployment_checks=include_deployment_checks,
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/core/management/base.py", line 377, in _run_checks
return checks.run_checks(**kwargs)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/core/checks/registry.py", line 72, in run_checks
new_errors = check(app_configs=app_configs)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/core/checks/urls.py", line 40, in check_url_namespaces_unique
all_namespaces = _load_all_namespaces(resolver)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/core/checks/urls.py", line 57, in _load_all_namespaces
url_patterns = getattr(resolver, 'url_patterns', [])
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/utils/functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/urls/resolvers.py", line 584, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/utils/functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/urls/resolvers.py", line 577, in urlconf_module
return import_module(self.urlconf_name)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/www/wwwroot/geolocator/geolocator/urls.py", line 40, in <module>
url(r'^rest/', include(router.urls, namespace='rest')),
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/urls/conf.py", line 39, in include
'Specifying a namespace in include() without providing an app_name '
django.core.exceptions.ImproperlyConfigured: Specifying a namespace in include() without providing an app_name is not supported. Set the app_name attribute in the included module, or pass a 2-tuple containing the list of patterns and app_name instead.
^C(geolocator_venv) [root#76 geolocator]# clear
(geolocator_venv) [root#76 geolocator]# python manage.py runserver 76.neurosynthesis.com:19999
Watching for file changes with StatReloader
Performing system checks...
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/root/.pyenv/versions/3.7.2/lib/python3.7/threading.py", line 917, in _bootstrap_inner
self.run()
File "/root/.pyenv/versions/3.7.2/lib/python3.7/threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/utils/autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run
self.check(display_num_errors=True)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/core/management/base.py", line 390, in check
include_deployment_checks=include_deployment_checks,
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/core/management/base.py", line 377, in _run_checks
return checks.run_checks(**kwargs)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/core/checks/registry.py", line 72, in run_checks
new_errors = check(app_configs=app_configs)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/core/checks/urls.py", line 40, in check_url_namespaces_unique
all_namespaces = _load_all_namespaces(resolver)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/core/checks/urls.py", line 57, in _load_all_namespaces
url_patterns = getattr(resolver, 'url_patterns', [])
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/utils/functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/urls/resolvers.py", line 584, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/utils/functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/urls/resolvers.py", line 577, in urlconf_module
return import_module(self.urlconf_name)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/www/wwwroot/geolocator/geolocator/urls.py", line 40, in <module>
url(r'^rest/', include(router.urls, namespace='rest')),
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/urls/conf.py", line 39, in include
'Specifying a namespace in include() without providing an app_name '
django.core.exceptions.ImproperlyConfigured: Specifying a namespace in include() without providing an app_name is not supported. Set the app_name attribute in the included module, or pass a 2-tuple containing the list of patterns and app_name instead.
Any idea how to fix this?
I am using django 1.11 and django rest version 3.
and i used drf-nested routers . for makin path like /abc/{id}/xyz/where abc and xyz are two views from AbcViewSet and XyzViewSet.
urls.py
from rest_framework_nested import routers
router = routers.SimpleRouter()
router.register(r'abc',AbcViewset)
abc_router = routers.NestedSimpleRouter(router,r'abc', lookup='abc')
abc_router.register(r'xyz', XyzViewset, base_name='abc-xyz')
urlpatterns = [
url(r'', include(router.urls)),
]
And I got the following traceback. I dont know what is happening with the code and what the error exactly is?
Performing system checks...
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7fb79f505a60>
Traceback (most recent call last):
File "/home/johan/.local/lib/python3.6/site-packages/django/utils/autoreload.py", line 227, in wrapper
fn(*args, **kwargs)
File "/home/johan/.local/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 125, in inner_run
self.check(display_num_errors=True)
File "/home//.local/lib/python3.6/site-packages/django/core/management/base.py", line 359, in check
include_deployment_checks=include_deployment_checks,
File "/home/johan/.local/lib/python3.6/site-packages/django/core/management/base.py", line 346, in _run_checks
return checks.run_checks(**kwargs)
File "/home/johan/.local/lib/python3.6/site-packages/django/core/checks/registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "/home/johan/.local/lib/python3.6/site-packages/django/core/checks/urls.py", line 16, in check_url_config
return check_resolver(resolver)
File "/home/johan/.local/lib/python3.6/site-packages/django/core/checks/urls.py", line 26, in check_resolver
return check_method()
File "/home/johan/.local/lib/python3.6/site-packages/django/urls/resolvers.py", line 254, in check
for pattern in self.url_patterns:
File "/home/johan/.local/lib/python3.6/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/johan/.local/lib/python3.6/site-packages/django/urls/resolvers.py", line 405, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/johan/.local/lib/python3.6/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/johan/.local/lib/python3.6/site-packages/django/urls/resolvers.py", line 398, in urlconf_module
return import_module(self.urlconf_name)
File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/johan/Documents/Abc/backend/abc/urls.py", line 24, in <module>
from rest_framework.documentation import include_docs_urls
File "/home/johan/.local/lib/python3.6/site-packages/rest_framework/documentation.py", line 6, in <module>
from rest_framework.schemas import SchemaGenerator, get_schema_view
File "/home/johan/.local/lib/python3.6/site-packages/rest_framework/schemas/__init__.py", line 25, in <module>
from .generators import SchemaGenerator
File "/home/johan/.local/lib/python3.6/site-packages/rest_framework/schemas/generators.py", line 18, in <module>
from rest_framework.compat import (
ImportError: cannot import name 'URLPattern'
How can this error be resolved?
I'm trying to create a simple registration form using django1.11.5
I created a project called mysite using the command:
django-admin.py startproject mysite .
And I have created an app called account using the code:
python manage.py startapp account
In the urls.py file of the folder mysite I specified the urlto be accessed as follows:
from django.conf.urls import url, include
from django.contrib import admin
urlpatterns = [
url(r'^account/',include(account.urls)),
url(r'^admin/', admin.site.urls),
]
However when I'm trying to migrate or runserver I'm getting the following error.
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x00000273BFBDFC80>
Traceback (most recent call last):
File "C:\Users\Welcome\django\myvenv\lib\site-packages\django\utils\autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "C:\Users\Welcome\django\myvenv\lib\site-packages\django\core\management\commands\runserver.py", line 125, in inner_run
self.check(display_num_errors=True)
File "C:\Users\Welcome\django\myvenv\lib\site-packages\django\core\management\base.py", line 359, in check
include_deployment_checks=include_deployment_checks,
File "C:\Users\Welcome\django\myvenv\lib\site-packages\django\core\management\base.py", line 346, in _run_checks
return checks.run_checks(**kwargs)
File "C:\Users\Welcome\django\myvenv\lib\site-packages\django\core\checks\registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\Users\Welcome\django\myvenv\lib\site-packages\django\core\checks\urls.py", line 16, in check_url_config
return check_resolver(resolver)
File "C:\Users\Welcome\django\myvenv\lib\site-packages\django\core\checks\urls.py", line 26, in check_resolver
return check_method()
File "C:\Users\Welcome\django\myvenv\lib\site-packages\django\urls\resolvers.py", line 254, in check
for pattern in self.url_patterns:
File "C:\Users\Welcome\django\myvenv\lib\site-packages\django\utils\functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\Welcome\django\myvenv\lib\site-packages\django\urls\resolvers.py", line 405, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Users\Welcome\django\myvenv\lib\site-packages\django\utils\functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\Welcome\django\myvenv\lib\site-packages\django\urls\resolvers.py", line 398, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Users\Welcome\AppData\Local\Programs\Python\Python36\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
File "C:\Users\Welcome\django\mysite\urls.py", line 19, in <module>
url(r'^account/',include(account.urls)),
NameError: name 'account' is not defined
So can someone please help. I'm new at this
When you 'include' urls, the reference to the app containing the urls should be a string like so:
from django.conf.urls import url, include
from django.contrib import admin
urlpatterns = [
...
url(r'^account/', include('account.urls')),
...
]
You are trying to import the actual app, but that is not necessary in this case.
Does that make sense?
I'm trying to get through a Django tutorial and I'm running into a syntax error when I try to run manage.py runserver. The error is below.
(C:\Users\Scott\Anaconda3) C:\Users\Scott\Desktop\django
tutorials\mysite>manage.py runserver
Performing system checks...
Unhandled exception in thread started by <function
check_errors.<locals>.wrapper at 0x000001705F6D48C8>
Traceback (most recent call last):
File "C:\Users\Scott\Anaconda3\lib\site-packages\django\utils\autoreload.py", line 227, in wrapper
fn(*args, **kwargs)
File "C:\Users\Scott\Anaconda3\lib\site-packages\django\core\management\commands\runserver.py", line 125, in inner_run
self.check(display_num_errors=True)
File "C:\Users\Scott\Anaconda3\lib\site-packages\django\core\management\base.py", line 359, in check
include_deployment_checks=include_deployment_checks,
File "C:\Users\Scott\Anaconda3\lib\site-packages\django\core\management\base.py", line 346, in _run_checks
return checks.run_checks(**kwargs)
File "C:\Users\Scott\Anaconda3\lib\site-packages\django\core\checks\registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\Users\Scott\Anaconda3\lib\site-packages\django\core\checks\urls.py", line 16, in check_url_config
return check_resolver(resolver)
File "C:\Users\Scott\Anaconda3\lib\site-packages\django\core\checks\urls.py", line 26, in check_resolver
return check_method()
File "C:\Users\Scott\Anaconda3\lib\site-packages\django\urls\resolvers.py", line 254, in check
for pattern in self.url_patterns:
File "C:\Users\Scott\Anaconda3\lib\site-packages\django\utils\functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\Scott\Anaconda3\lib\site-packages\django\urls\resolvers.py", line 405, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Users\Scott\Anaconda3\lib\site-packages\django\utils\functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\Scott\Anaconda3\lib\site-packages\django\urls\resolvers.py", line 398, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Users\Scott\Anaconda3\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 674, in exec_module
File "<frozen importlib._bootstrap_external>", line 781, in get_code
File "<frozen importlib._bootstrap_external>", line 741, in source_to_code
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
File "C:\Users\Scott\Desktop\django tutorials\mysite\mysite\urls.py", line 22
]
^
SyntaxError: invalid syntax
mysite\urls.py is below. I'm not sure what is wrong with the syntax, or why it's pointing to the bracket.
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index')]
Please use a list type for urlpatterns.
Leave a comma at the end of the list:
urlpatterns = [
url(r'^$', views.index, name='index'),
]