Django url app命名空间冲突

时间:2015-03-18 17:18:59

标签: python django

我有一个有两个应用程序的Django网站。一个是api,另一个是前端。出于某种原因,前端的网址正在解决这个问题......

为Game_Server /游戏/ 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民意调查应用程序中遵循的过程非常相同......

1 个答案:

答案 0 :(得分:1)

games/urls.py中你有:

from api import views

您想要导入games视图:

from games import views