5. Django 2.1.7 runserver啟動(dòng)直接報(bào)錯(cuò) django.core.exceptions.ImproperlyConfigured: Passing a 3-tuple t...

在其他辦公電腦創(chuàng)建的Django項(xiàng)目 2.2.1 版本都可以直接 runserver 啟動(dòng)服務(wù)正常。
但是本地創(chuàng)建的項(xiàng)目,只要執(zhí)行python3 manage.py runserver 就直接報(bào)錯(cuò)。

錯(cuò)誤詳細(xì)日志

F:\pythonProject\mysite>python3 manage.py runserver
Performing system checks...

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x000001E95E2177B8>
Traceback (most recent call last):
  File "G:\Python3\Python37\lib\site-packages\django\urls\conf.py", line 17, in include
    urlconf_module, app_name = arg
ValueError: too many values to unpack (expected 2)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "G:\Python3\Python37\lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
    fn(*args, **kwargs)
  File "G:\Python3\Python37\lib\site-packages\django\core\management\commands\runserver.py", line 117, in inner_run
    self.check(display_num_errors=True)
  File "G:\Python3\Python37\lib\site-packages\django\core\management\base.py", line 379, in check
    include_deployment_checks=include_deployment_checks,
  File "G:\Python3\Python37\lib\site-packages\django\core\management\base.py", line 366, in _run_checks
    return checks.run_checks(**kwargs)
  File "G:\Python3\Python37\lib\site-packages\django\core\checks\registry.py", line 71, in run_checks
    new_errors = check(app_configs=app_configs)
  File "G:\Python3\Python37\lib\site-packages\django\core\checks\urls.py", line 40, in check_url_namespaces_unique
    all_namespaces = _load_all_namespaces(resolver)
  File "G:\Python3\Python37\lib\site-packages\django\core\checks\urls.py", line 57, in _load_all_namespaces
    url_patterns = getattr(resolver, 'url_patterns', [])
  File "G:\Python3\Python37\lib\site-packages\django\utils\functional.py", line 37, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "G:\Python3\Python37\lib\site-packages\django\urls\resolvers.py", line 533, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "G:\Python3\Python37\lib\site-packages\django\utils\functional.py", line 37, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "G:\Python3\Python37\lib\site-packages\django\urls\resolvers.py", line 526, in urlconf_module
    return import_module(self.urlconf_name)
  File "G:\Python3\Python37\lib\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 "F:\pythonProject\mysite\mysite\urls.py", line 20, in <module>
    url(r'^admin/', include(admin.site.urls)),
  File "G:\Python3\Python37\lib\site-packages\django\urls\conf.py", line 27, in include
    'provide the namespace argument to include() instead.' % len(arg)
django.core.exceptions.ImproperlyConfigured: Passing a 3-tuple to include() is not supported. Pass a 2-tuple containing the list of patterns and app_name, and provide the namespace
 argument to include() instead.

F:\pythonProject\mysite>

奇怪就在于我啟動(dòng)其他電腦創(chuàng)建的項(xiàng)目完全是沒問題的,就是本機(jī)新建的項(xiàng)目會(huì)報(bào)錯(cuò)。而且是一句代碼都沒寫。

導(dǎo)致錯(cuò)誤是Django默認(rèn)創(chuàng)建的urls.py存在問題

from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
]

解決問題

最后調(diào)試了下,發(fā)現(xiàn)Django 創(chuàng)建項(xiàng)目后的 urls.py 文件有問題,啟動(dòng)就直接報(bào)錯(cuò)。修改如下即可解決問題。

from django.contrib import admin
from django.urls import include, path # 增加導(dǎo)入include方法

urlpatterns = [
    path('admin/', admin.site.urls),
]

啟動(dòng)服務(wù)成功,如下:

F:\pythonProject\mysite>python3 manage.py runserver
Performing system checks...

System check identified no issues (0 silenced).

You have 15 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
June 03, 2019 - 22:50:30
Django version 2.1.7, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 模塊間聯(lián)系越多,其耦合性越強(qiáng),同時(shí)表明其獨(dú)立性越差( 降低耦合性,可以提高其獨(dú)立性)。軟件設(shè)計(jì)中通常用耦合度和內(nèi)聚...
    riverstation閱讀 2,230評(píng)論 0 8
  • 已經(jīng)同步到gitbook,想閱讀的請轉(zhuǎn)到gitbook: Django 1.10 中文文檔 Let’s learn...
    leyu閱讀 2,010評(píng)論 1 8
  • 點(diǎn)我查看本文集的說明及目錄。 本項(xiàng)目相關(guān)內(nèi)容包括: 實(shí)現(xiàn)過程: CH7 創(chuàng)建在線商店 CH8 管理支付和訂單 CH...
    學(xué)以致用123閱讀 3,873評(píng)論 0 6
  • 創(chuàng)建你的第一個(gè)Django應(yīng)用 讓我們通過一個(gè)實(shí)例來學(xué)習(xí)。通過這個(gè)教程,我們將會(huì)帶你過一遍創(chuàng)建一個(gè)基本的投票應(yīng)用的...
    轉(zhuǎn)身丶即天涯閱讀 396評(píng)論 0 3
  • 一、Django框架前言知識(shí): 1、C/S和B/S的區(qū)別: C/S結(jié)構(gòu)軟件:客戶端/服務(wù)端軟件,即客戶端要自己下載...
    月下獨(dú)酌123閱讀 5,151評(píng)論 0 36

友情鏈接更多精彩內(nèi)容