Reputation: 101
i am interested in learning Django for python. Therefore i followed their Tutorial - yet now i am stuck at the following point of the second tutorial element:
Problem: According to the tutorial i shall run a "Database Migration" by using the following codes:
python3 manage.py makemigrations
python3 manage.py migratecode
I do receive the following error message on execution of the first command (makemigrations):
> (django_second_test) sebastian@sebastian-Lenovo-Y50-70
> ~/Dokumente/py_virtualenv/django_virtualenv/django_second_test/locallibrary/locallibrary
> $ python3 manage.py makemigrations Traceback (most recent call last):
> File "manage.py", line 15, in <module>
> execute_from_command_line(sys.argv) File "/home/sebastian/Dokumente/py_virtualenv/django_virtualenv/django_second_test/lib/python3.5/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
> utility.execute() File "/home/sebastian/Dokumente/py_virtualenv/django_virtualenv/django_second_test/lib/python3.5/site-packages/django/core/management/__init__.py", line 365, in execute
> self.fetch_command(subcommand).run_from_argv(self.argv) File "/home/sebastian/Dokumente/py_virtualenv/django_virtualenv/django_second_test/lib/python3.5/site-packages/django/core/management/base.py",
> line 288, in run_from_argv
> self.execute(*args, **cmd_options) File "/home/sebastian/Dokumente/py_virtualenv/django_virtualenv/django_second_test/lib/python3.5/site-packages/django/core/management/base.py",
> line 332, in execute
> self.check() File "/home/sebastian/Dokumente/py_virtualenv/django_virtualenv/django_second_test/lib/python3.5/site-packages/django/core/management/base.py",
> line 364, in check
> include_deployment_checks=include_deployment_checks, File "/home/sebastian/Dokumente/py_virtualenv/django_virtualenv/django_second_test/lib/python3.5/site-packages/django/core/management/base.py",
> line 351, in _run_checks
> return checks.run_checks(**kwargs) File "/home/sebastian/Dokumente/py_virtualenv/django_virtualenv/django_second_test/lib/python3.5/site-packages/django/core/checks/registry.py",
> line 73, in run_checks
> new_errors = check(app_configs=app_configs) File "/home/sebastian/Dokumente/py_virtualenv/django_virtualenv/django_second_test/lib/python3.5/site-packages/django/core/checks/urls.py",
> line 40, in check_url_namespaces_unique
> all_namespaces = _load_all_namespaces(resolver) File "/home/sebastian/Dokumente/py_virtualenv/django_virtualenv/django_second_test/lib/python3.5/site-packages/django/core/checks/urls.py",
> line 57, in _load_all_namespaces
> url_patterns = getattr(resolver, 'url_patterns', []) File "/home/sebastian/Dokumente/py_virtualenv/django_virtualenv/django_second_test/lib/python3.5/site-packages/django/utils/functional.py",
> line 36, in __get__
> res = instance.__dict__[self.name] = self.func(instance) File "/home/sebastian/Dokumente/py_virtualenv/django_virtualenv/django_second_test/lib/python3.5/site-packages/django/urls/resolvers.py",
> line 536, in url_patterns
> patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) File
> "/home/sebastian/Dokumente/py_virtualenv/django_virtualenv/django_second_test/lib/python3.5/site-packages/django/utils/functional.py",
> line 36, in __get__
> res = instance.__dict__[self.name] = self.func(instance) File "/home/sebastian/Dokumente/py_virtualenv/django_virtualenv/django_second_test/lib/python3.5/site-packages/django/urls/resolvers.py",
> line 529, in urlconf_module
> return import_module(self.urlconf_name) File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
> return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 986, in _gcd_import File
> "<frozen importlib._bootstrap>", line 969, in _find_and_load File
> "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
> File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
> File "<frozen importlib._bootstrap_external>", line 665, in
> exec_module File "<frozen importlib._bootstrap>", line 222, in
> _call_with_frames_removed File "/home/sebastian/Dokumente/py_virtualenv/django_virtualenv/django_second_test/locallibrary/locallibrary/locallibrary/urls.py",
> line 20, in <module>
> url(r'^admin/', admin.site.urls), NameError: name 'url' is not defined
I have rechecked my code and even copy_pasted it according to the tutorial specifications - but as a beginner (also in Python) i do struggle to understand what is going on.
Link to tutorial page: Link to second part of Django Tutorial
Other information: virtual environment is active (activated via "source activate"); Python3.5 is in virtual environment. Fist part of tutoriual (setup of virtual env and python and installment of django via pip3 was successful). I am on mint linux.
Thank you all for your help!
Sebastian
Upvotes: 0
Views: 1716
Reputation: 308899
You are getting the NameError
because you are missing the following import:
from django.conf.urls import url
This is because you created the project using Django 2.0, but the tutorial was written for Django 1.11. You get NameError
because the default urls.py
in Django 2.0 imports path()
by instead of url()
:
from django.urls import path
I recommend that you either use Django 2.0 with the official tutorial for Django 2.0, or use the Mozilla tutorial with Django 1.11. If your version of Django doesn't match the version the tutorial was written for, you are more likely to hit issues like this, which can be frustrating when you're new to Django.
If you stick with the Mozilla tutorial, you can install the latest point release of Django 1.11 with:
pip3 install "django<2"
Upvotes: 1