在django python中不显示HttpResponse

unftdfkk  于 2023-08-08  发布在  Go
关注(0)|答案(3)|浏览(103)

settings.py

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'sample'
]

字符串
样品/views.py

from django.shortcuts import render
from django.http import HttpResponse

def hello(request):
    return HttpResponse("hello world")


mainapp/urls.py

from django.contrib import admin
from django.urls import path
from sample import views

urlpatterns = [
    path('hello/',views.hello),
    path('admin/', admin.site.urls)
]


但是当我运行python manage.py runserver时,它不会显示8000/hello/页面

hof1towb

hof1towb1#

我已经在一个新的Django项目中重新创建了你的应用程序,它运行得很好
我分享了应用程序的代码和目录结构,希望这对你有帮助。
网址:settings.py

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'sample'
 ]

字符串
网址:urls.py

from django.contrib import admin
from django.urls import path
from sample import views

urlpatterns = [
    path('hello/',views.hello),
    path('admin/', admin.site.urls),
]


网址:views.py

from django.http import HttpResponse

def hello(request):
    return HttpResponse("hello world")


的数据

lvmkulzt

lvmkulzt2#

在manage.py文件所在的文件夹中运行**python manage.py runserver**。

m3eecexj

m3eecexj3#

它不是页面8000/hello,而是(默认)端口8000,页面“hello”。
尝试运行:127.0.0.1:8000/hello/

相关问题