2017-04-13 54 views
0

我一直在嘗試兩次以將第二個應用程序添加到我的Django站點,但它導致某種錯誤。如何將兩個應用程序/頁面添加到我的Django站點?

我遵循了來自youtube的指示,這對我有很大的幫助,但現在我堅持添加第二個頁面。我的第一個工作很好。

這是我的主要url.py:

from django.conf.urls import url, include 

from django.contrib import admin 

urlpatterns = [ 

url(r'^admin/', admin.site.urls), 

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

url(r'^', include('login.urls')), 

] 

這是我的主要settings.py:

INSTALLED_APPS = [ 

'login', 

'table', 

.... 
TEMPLATES = [ 

{ 
    'BACKEND': 'django.templates.backends.django.DjangoTemplates', 
    'DIRS': [], 
    'APP_DIRS': True, 
    'OPTIONS': { 
     'context_processors': [ 
      'django.templates.context_processors.debug', 
      'django.templates.context_processors.request', 
      'django.contrib.auth.context_processors.auth', 
      'django.contrib.messages.context_processors.messages', 
     ], 
    }, 
}, 
] 

這是我的工作頁面url.py:

from django.conf.urls import url, include 

from . import views 


urlpatterns = [ 

url(r'^$', views.index, name='index'), 

] 

這是我的工作頁面view.py:

from django.shortcuts import render 


def index(request): 

return render(request,'login/login.html', {'content': ['username', 

'password']}) 

這是我的非工作頁面url.py:

from django.conf.urls import url, include 

from . import views 



urlpatterns = [ 

url(r'^$', views.index, name = 'index'), 

] 

這是我的非工作頁面view.py:

from django.shortcuts import render 

from django.http import HttpResponse 


def index(request): 



return render(request,'table/table.html') 

到目前爲止,我已經想好了指數的(要求)是一個問題,因爲它們都具有名稱「視圖」和相同的函數名稱......?

我不知道要在「錯誤頁面」上看什麼,也不知道向您展示什麼,對不起。我感謝任何幫助。謝謝。

「在上面的異常( 'django的')的處理,另一個異常: C:\ python36 \ lib中\站點包\ django的\芯\處理程序\ exception.py在內 響應= get_response(請求)... ▼本地變量 變量值 EXC ModuleNotFoundError( 「無模塊名爲 'django.templates'」) get_response
>>> > 要求 「

編輯:我總是命名我的所有模板文件夾模板。雖然在第二個應用程序中創建它時,我錯誤地命名了它,但它通過重構進行了更改。

我覺得這是現在我的錯誤:

異常類型:ModuleNotFoundError在/ 異常值:沒有名爲 'django.templates'

+0

我不確定,但給定錯誤**沒有名爲'django.templates'的模塊**我認爲您可能在該應用程序的某處導入語句或設置文件中的拼寫錯誤中寫入了錯誤。有一個模塊django.template,但沒有django.templates。 – dentemm

+0

是的我相信這是我的錯誤信息,如果我理解正確的話: 異常類型:ModuleNotFoundError at/ 異常值:沒有名爲'django.templates'的模塊 – Kimmisen

+0

您是否找到它?如果沒有,請檢查您的TEMPLATES設置(有一些** django.template.x **模塊設置)或可能您的views.py或forms.py文件導入語句:**從django.templates導入x **。您很可能需要將_django.templates_更改爲_django.template_某處。 – dentemm

回答

0

該錯誤消息指出ÿ你指的是某處的django.templates。這個模塊在django中不存在,但是django.template會。您可以在settings.py文件中找到幾個django.template.x語句。

用django.template.x替換django.templates.x,你很好走!

0

在你的urls.py,指定這樣的APP_NAME模塊:

# ...imports... 

app_name = 'tables' 
urlpatterns = [ 
#... 
] 

URL的名稱然後可以通過你的模板,通過表格進行訪問:指數

+0

謝謝,我添加了它,雖然它沒有幫助這個特殊問題......看起來它可能與模板有關。閱讀錯誤非常困難,我非常感謝你的善意。 :) – Kimmisen

相關問題