Windows 10
Python 3.7.3
Djangoでリンクの設定をしたいのですが、これらを書いた後にpython manage.py runserverでサーバーを動かそうとするとエラーが表示されサーバーが動きません。
Python
1views.py 2 3def index(request): 4 return render(request,'index.html') 5 6def hello(request): 7 return render(request, 'hello.html') 8 9 10project/urls.py 11 12from django.conf.urls import url 13 14urlpatterns = [ 15 path('admin/', admin.site.urls), 16 path('', include('app.urls')) 17 18 url('', include(('app.urls', 'hello'), namespace='hello')), 19] 20 21 22app/urls.py 23 24from django.conf.urls import url 25 26urlpatterns = [ 27 path('', views.index, name='index'), 28 29 url('', view.hello, name='hello'), 30] 31 32 33index.html 34 35<a href="{% url 'hello:hello' %}">Hello World!</a> 36 37<a href="{% url 'hello' %}">Hello World!</a> 38
これらを書かなければサーバーは動きます。
何か書き方がおかしいのでしょうか?
やりたい事はシンプルにリンクを貼りたいだけです。
今の状態はindex.htmlと同じ階層にhello.htmlが入っています。
project\app\templates\hello.html
テラテイルやいろんなサイトを見たのですがなかなか解決が出来ずに困っています。
app/urls.pyを使わずにproject/urls.pyに直接
Python
1path('', views.hello, name='hello'),
と書いたりしても動かず、この部分にSyntaxError: invalid syntaxというエラーが出ています。
何か書き方がおかしいのだと思います。
試しに
Python
1url('', include(('app.urls', 'hello'), namespace='hello')),
と書いても表示されません。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/04/08 06:33
2019/04/08 08:19
2019/04/08 11:41