英文:
I followed the django example exactly. But it doesn't work
问题
我按照django的示例完全操作了。但它不起作用。网页只是给我显示火箭。
我的项目名称:web
应用程序名称:main
web.settings.py =>
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'main',
]
web.urls.py =>
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('main/', include('main.urls')),
path('admin/', admin.site.urls),
]
main.urls.py =>
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
]
main.views.py =>
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world. You're at the polls index.")
我希望网页对我显示 "Hello, world. You're at the polls index."。
英文:
**
I followed the django example exactly. But it doesn't work. Web page just show the rocket to me.**
my project name: web
app name: main
web.settings.py
=>
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'main',
]
web.urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('main/', include('main.urls')),
path('admin/', admin.site.urls),
]
main.urls.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
]
main.views.py
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world. You're at the polls index.")
I hope web page shows "Hello, world. You're at the polls index." to me.
答案1
得分: 1
在你的主要URL文件中,你已经设置了:
urlpatterns = [
path('main/', include('main.urls')),
path('admin/', admin.site.urls),
]
这实际上意味着,你需要在浏览器中访问 localhost:8000/main
来访问"main"应用中的URL。如果你想在浏览器中不指定main
来访问,那么将其更改为:
urlpatterns = [
path('', include('main.urls')),
path('admin/', admin.site.urls),
]
英文:
In your main urls file you have set:
urlpatterns = [
path('main/', include('main.urls')),
path('admin/', admin.site.urls),
]
Which actually means, that you need to go for localhost:8000/main
for your urls in "main" app. If you want to do it without specifying main
in the url in your browser, then change it to:
urlpatterns = [
path('', include('main.urls')),
path('admin/', admin.site.urls),
]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论