[英]After linking urls&views “hello world” is not visible in django
i have just now started learning the django basics,but i have been keeping on facing a problem with the urls & views.我刚刚开始学习 django 基础知识,但我一直面临着网址和视图的问题。 i do not get the "Hello world" after i reload or even try adding myapp name in the url我重新加载后没有得到“Hello world”,甚至尝试在 url 中添加 myapp 名称
wrote this code for the project url为项目 url 编写了此代码
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('', include('calc.urls')),
path('admin/', admin.site.urls),
]
wrote this for myapp urls为 myapp 网址写的
from django.urls import path
from . import views
urlpatterns = [
path('', views.home, name='home'),
]
wrote this for the views写这个是为了意见
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def home(request):
return HttpResponse("Hello world");
what is the mistake i am doing?我在做什么错?
link: http://127.0.0.1:8000/calc
链接: http://127.0.0.1:8000/calc
You are not setting the correct URL.您没有设置正确的 URL。 Also have you added your in installed apps?您还添加了已安装的应用程序吗? if yes then visit: http://127.0.0.1:8000
如果是,请访问: http://127.0.0.1:8000
or add calc
in your url to use http://127.0.0.1:8000/calc
或在您的 url 中添加calc
以使用http://127.0.0.1:8000/calc
urlpatterns = [
path('calc', views.home, name='home'),
]
Is your myapp urls file inside a folder called calc?您的 myapp urls 文件是否位于名为 calc 的文件夹中? If it isn't then try doing something like this:如果不是,请尝试执行以下操作:
Change include('calc.urls')
to include('\the folder name in which myapp urls is in\.urls')
include('calc.urls')
更改为include('\the folder name in which myapp urls is in\.urls')
Then use the http://127.0.0.1:8000
and it should work.然后使用http://127.0.0.1:8000
它应该可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.