Crysistec Crysistec - 8 days ago 7
Python Question

the 'package' argument is required to perform a relative import for

I'm not sure what is causing this error I'm looking to try and runsever on django from windows PowerShell but im am getting that error and this wall of issues.

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x03D366A8>
Traceback (most recent call last):
File "D:\Python\lib\site-packages\django\utils\autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "D:\Python\lib\site-packages\django\core\management\commands\runserver.py", line 121, in inner_run
self.check(display_num_errors=True)
File "D:\Python\lib\site-packages\django\core\management\base.py", line 374, in check
include_deployment_checks=include_deployment_checks,
File "D:\Python\lib\site-packages\django\core\management\base.py", line 361, in _run_checks
return checks.run_checks(**kwargs)
File "D:\Python\lib\site-packages\django\core\checks\registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "D:\Python\lib\site-packages\django\core\checks\urls.py", line 14, in check_url_config
return check_resolver(resolver)
File "D:\Python\lib\site-packages\django\core\checks\urls.py", line 24, in check_resolver
for pattern in resolver.url_patterns:
File "D:\Python\lib\site-packages\django\utils\functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "D:\Python\lib\site-packages\django\urls\resolvers.py", line 313, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "D:\Python\lib\site-packages\django\utils\functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "D:\Python\lib\site-packages\django\urls\resolvers.py", line 306, in urlconf_module
return import_module(self.urlconf_name)
File "D:\Python\lib\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 "D:\Python\courseworkupload\courseworkupload\urls.py", line 26, in <module>
url(r'^upload/', include('.upload.urls')),
File "D:\Python\lib\site-packages\django\conf\urls\__init__.py", line 50, in include
urlconf_module = import_module(urlconf_module)
File "D:\Python\lib\importlib\__init__.py", line 121, in import_module
raise TypeError(msg.format(name))
TypeError: the 'package' argument is required to perform a relative import for '.upload.urls'


This was done after i ran python manage.py runserver

Any help on the issue would be great

Edit: Adding tree below

C:.
│ db.sqlite3
│ manage.py

├───.idea
│ courseworkupload.iml
│ misc.xml
│ modules.xml
│ workspace.xml

├───courseworkupload
│ │ settings.py
│ │ urls.py
│ │ wsgi.py
│ │ __init__.py
│ │
│ └───__pycache__
│ settings.cpython-35.pyc
│ urls.cpython-35.pyc
│ wsgi.cpython-35.pyc
│ __init__.cpython-35.pyc

└───upload
│ admin.py
│ apps.py
│ forms.py
│ models.py
│ tests.py
│ urls.py
│ views.py
│ __init__.py

├───migrations
│ __init__.py

├───templates
└───__pycache__
admin.cpython-35.pyc
forms.cpython-35.pyc
models.cpython-35.pyc
urls.cpython-35.pyc
views.cpython-35.pyc
__init__.cpython-35.pyc

Answer

The leading dot in include('.upload.urls') is causing the problem.

Assuming that upload is in your project directory (the one that contains manage.py), changing it to upload.urls should work.

url(r'^upload/', include('upload.urls')),