[英]I am not able to open admin page in Django Framework
I am trying to build a web app using the Django Framework.我正在尝试使用 Django 框架构建 web 应用程序。 When, I go into localhost:8000/admin the browser says: Firefox can't establish a connection to the server at 127.0.0.1:8000.当我 go 进入 localhost:8000/admin 时,浏览器显示:Firefox 无法在 127.0.0.1:8000 建立与服务器的连接。
I am using PyCharm:我正在使用 PyCharm:
This is the error that comes up in the terminal:这是终端中出现的错误:
Not Found: /未找到: /
[21/Apr/2020 15:18:20] "GET / HTTP/1.1" 404 2031 Following which the server cuts off [21/Apr/2020 15:18:20] "GET / HTTP/1.1" 404 2031 随后服务器中断
my app/urls:我的应用程序/网址:
from django.urls import path
from . import views
urlpatterns = [
path('', views.index),
]
And my project/urls:还有我的项目/网址:
from django.contrib import admin from django.urls import path, include from django.contrib import admin from django.urls 导入路径,包括
urlpatterns = [
path('admin/', admin.site.urls),
path('KMIO_page/', include('KMIO_app1.urls')),
]
In your logs, it says that you visited the home ( "/"
) path, not the path for your admin ( "/admin"
).在您的日志中,它说您访问了主路径( "/"
),而不是您的管理员路径( "/admin"
)。 The urls.py
files seem to be good. urls.py
文件似乎很好。 However, you could add in your app/urls.py
file, outside of the urlpatterns
variable, the variable app_name
and assign it the value of KMIO_app1
or the name of your app.但是,您可以在您的app/urls.py
文件中,在urlpatterns
变量之外添加变量app_name
并为其分配KMIO_app1
的值或您的应用程序的名称。 Last but not least, you could add in your app/urls.py
file a slash ( "/"
) for your home directory.最后但同样重要的是,您可以在您的app/urls.py
文件中为您的主目录添加一个斜杠( "/"
)。 For example:例如:
app/urls.py
from django.urls import path
from . import views
urlpatterns = [
path('/', views.index),
]
I hope that helps.我希望这会有所帮助。 Please let me know if that fixes your issue.请让我知道这是否能解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.