gpt4 book ai didi

python - Django url应用命名空间冲突

转载 作者:太空宇宙 更新时间:2023-11-04 05:53:12 24 4
gpt4 key购买 nike

我有一个包含两个应用程序的 Django 站点。一个是 api,另一个是前端。出于某种原因,前端的 url 正在解析为 api...

game_server/games/urls.py:

from django.conf.urls import patterns, url
from api import views

urlpatterns = patterns('',
url(r'^$', views.index, name = 'index'),
url(r'^tictactoe/$', views.tictactoe, name = 'tictactoe'),
)

game_server/api/urls.py:

from django.conf.urls import patterns, url
from api import views

urlpatterns = patterns('',
url(r'^$', views.index, name = 'index'),
url(r'^tictactoe/$', views.tictactoe, name = 'tictactoe'),
)

游戏服务器/游戏服务器/urls.py:

from django.conf.urls import patterns, include, url
from django.contrib import admin

urlpatterns = patterns('',
url(r'^games/', include('games.urls', namespace="games", app_name="games")),
url(r'^admin/', include(admin.site.urls)),
url(r'^api/', include('api.urls', namespace="api", app_name="api"))
)

但是每当我访问 127.0.0.1:8000/games/tictactoe 时,它​​都会给我 game_server/api/views.py 中的 tictactoe View (对于索引也是如此)

我确定这很明显,但我认为我在 Django 民意调查应用程序中遵循的过程几乎完全相同......

最佳答案

games/urls.py 中你有:

from api import views

您想改为导入 games View :

from games import views

关于python - Django url应用命名空间冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29128589/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com