2017-12-12 21 views
0

次のurls.pyファイルがDjangoプロジェクトにあります。私は、URLとパスに関連する最新の構文に関するエラーが発生しています。DjangoのURLファイルのエラー

Iは、個人用サイト(最も外側のディレクトリ)にurl.pyあるURLをファイルに持たコードである:

from django.urls import path 
from django.conf.urls import url, include 


urlpatterns = [ 
    path(r'^$', include('aboutme.urls')), 

] 

エラーメッセージは、次のとおりで

Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order: 
^$ 
The empty path didn't match any of these. 

実際のアプリ(ウェブサイトフォルダ)は「aboutme」と呼ばれ、urls.pyファイルは次のようになります:

from django.urls import path 
from django.conf.urls import url, include 
from .import views #this is the main thing we are going to be doing ....returning views! 

urlpatterns = [ 

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

] 

誰でも正しい構文を理解しているか、間違っていると思いますか?

UPDATE:

私はまた戻って、(以前に作業バージョンにあった)管理コマンドが含まれるようにメイン個人用サイトのurl.pyファイルを更新しようとしました。コードと結果のエラーは、以下の通りである:

は、このコードを試しました:

Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order: 
admin/ 
The empty path didn't match any of these. 
+1

更新されたコードの 'r '''にスペースがあります。空の文字列 ''''を使うべきです。 – Alasdair

答えて

2

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


urlpatterns = [ 
    path('admin/', admin.site.urls), 
    path(r' ', include('aboutme.urls')), 

] 

エラーがurls.pyファイルに^$を削除します。

from django.urls import path 
from django.conf.urls import url, include 

urlpatterns = [ 
    path(r'', include('aboutme.urls')), 
] 

、アプリurls.py中:

from django.urls import path 
from django.conf.urls import url, include 
from .import views #this is the main thing we are going to be doing 

app_name="myappname" 
urlpatterns = [ 
    path(r'', views.index,name='index'), 
] 

ジャンゴ2.0では、あなたがpath()を使用している場合、彼らはもはや必要ありません。

関連リンク:https://code.djangoproject.com/ticket/28691

+0

私はそれを試しましたが、それは次のようになります。mysite.urlsで定義されているURLconfを使用して、Djangoは次のURLパターンを次の順序で試しました: 空のパスがこれらと一致しませんでした。 Django設定ファイルにDEBUG = Trueが設定されているため、このエラーが表示されます。これをFalseに変更すると、Djangoは標準404ページを表示します。 – MissComputing

+0

これはもう必要ではないが、 'path()'では使われていないことではない。 'url()'はまだ存在していて、それを使って*使用します。 –

+0

ちょうど試しましたが、残念ながらまだ動作しません。アプリの名前を指定する必要はありますか? (私が接続しようとしているディレクトリ) – MissComputing