2017-02-24 50 views
-1

我是django框架中的新手 嘗試爲文件系統中的上載映像構建模板並在頁面上顯示此圖像。 首先我得到的錯誤首先,我在文件得到錯誤嘗試在django中運行服務器時系統檢查錯誤

"/home/tac/Desktop/myproject/myapp/urls.py", line 5, in <module> 
url(r'^$', 'list', name='list'), 

文件「/usr/local/lib/python2.7/dist-packages/django/conf/urls/ 初始化 py」爲,行85 ,url raise TypeError('在'include()'的情況下'視圖必須是可調用的或列表/元組') TypeError:在include()的情況下,視圖必須是可調用的或者列表/元組。

不知何故,我解決了這個錯誤,但之後,我面臨的另一個錯誤 enter image description here

的myapp/urls.py

from django.conf.urls import include, url 

urlpatterns = ('myapp.views', 
    url(r'^$', list, name='list'), 
    url(r'^list/$', list, name='list'), 
) 

的myproject/urls.py

from django.conf.urls import include, url 
from django.conf import settings 
from django.conf.urls.static import static 
from django.views.generic import RedirectView 
from django.contrib import admin 
# admin.autodiscover() 

urlpatterns = [ 
     (r'^myapp/', include('myapp.urls')), 
     (r'^$', 'myapp.views.index'), 
     (r'^admin/', include(admin.site.urls)), 
] 
static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) 

錯誤 線程由開始的異常處理10追蹤(最近呼叫最後): 文件「/usr/local/lib/python2.7/dist-packages/django/utils/autoreload.py」,第226行,封裝 fn(* args,** kwargs ) 文件「/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py」,行121,位於inner_run self.check(display_num_errors = True) 文件「/ usr/local/lib/python2.7/dist-packages/django/core/management/base.py「,第420行,檢查 raise SystemCheckError(msg) django.core.management.base.SystemCheckError:SystemCheckError:System檢查確定了一些問題:

錯誤: ?:(urls.E004)您的URL模式('^ $','myapp.views.index')無效。確保urlpatterns是url()實例的列表。 提示:嘗試使用url()而不是元組。 ?:(urls.E004)您的網址格式('^ admin /',([,,,,,d +)/(?P。+)/ $>,(無:無)^ auth/user/>,(None:None)^ auth/group />,auth)/ $>],'admin','admin'))無效。確保urlpatterns是url()實例的列表。 提示:嘗試使用url()而不是元組。 ?:((urls.E004))您的網址格式('^ myapp /',(,None,None))無效。確保urlpatterns是url()實例的列表。 提示:嘗試使用url()而不是元組。

系統檢查發現3個問題(0沉默)。

+0

複製到這裏你的urls.py文件 – Cadmus

+0

添加兩個urls.py @SnakeFcz –

+0

我發現在urls.py錯誤,我已經answerd belwo找到它,你需要附加靜態網址在urlpatterns列表 – Cadmus

回答

0
myproject/urls.py 

from django.conf.urls import include, url 
from django.conf import settings 
from django.conf.urls.static import static 
from django.views.generic import RedirectView 
from django.contrib import admin 
# admin.autodiscover() 

urlpatterns = [ 
     url(r'^myapp/', include('myapp.urls')), 
     url(r'^admin/', include(admin.site.urls)), 
] 
urlpatterns+= static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) 





myapp/urls.py 

from django.conf.urls import url 
from . import views 

urlpatterns = [ 

    # url(r'^$', views.list, name='list'), 
    url(r'^$', views.index, name='index'), 
    url(r'^list/$', views.list, name='list'), 
] 
+0

感謝它的工作!@SnakeFcz –

+0

好你很酷你去山雀 – Cadmus

0
from django.conf.urls import include, url 
from django.conf import settings 
from django.conf.urls.static import static 
from django.views.generic import RedirectView 
from django.contrib import admin 
# admin.autodiscover() 

urlpatterns = [ 
     url(r'^myapp/', include('myapp.urls')), 
     url(r'^$', 'myapp.views.index'), 
     url(r'^admin/', include(admin.site.urls)), 
] 
urlpatterns+= static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) 
+0

你能告訴你在哪個urls.py你在說myapp/urls.py還是myproject/urls.py @SnakeFcz –

+1

我會更新anwer – Cadmus

相關問題