我有一个包含两个应用程序的Django网站。一个是api,另一个是前端。由于某些原因,前端的网址正在解析为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'),
)


game_server / game_server / 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视图(索引也是如此)

我敢肯定这很明显,但是我想我几乎完全按照Django polls app的程序进行操作...

最佳答案

games/urls.py中,您具有:

from api import views


您想改为导入games视图:

from games import views

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

10-16 22:21