2016-07-31 21 views
0

我對django的環境很陌生,我嘗試創建一個url鏈接;然而,錯誤讀取沒有名爲'urls.py'的模塊

ImportError: No module named 'myprofile' 

因此,我卡在這裏問如何解決這個問題。我看過幾個論壇;然而,我無法解決這個問題。感謝您的幫助。

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

urlpatterns = [ 
    url(r'^$', views.index), 
    url(r'^myprofile$',include("myprofile.urls"), name = myprofile) 
] 
+0

名=「我的資料」 – e4c5

+0

我試過,但錯誤依然矗立 –

+0

你有我的資料目錄?它有一個urls.py嗎?它與這個文件有什麼關係? –

回答

0

假設你有一個名爲myprofile一個應用程序,其中包括一個views.py你應該形成你的網址如下所示:

from django.conf.urls import url 
from django.conf.urls import include 
from myprofile import views as myprofileViews 

urlpatterns = [ 
    url(r'^$', views.index), 
    url(r'^myprofile$', myprofileViews.SomeViewName) 
] 

您應該然後還要有myprofile/views.py以下代碼:

def SomeViewName(request): 
    return render(request, 'index.html', context) 
0

可能是因爲你在myprofile應用程序中缺少__init__.py。這是應用程序目錄中的文件,如果它是空的就足夠了。這個文件將使Python將該目錄識別爲一個模塊。

也看到了這個問題: Python error "ImportError: No module named"