简体   繁体   English

Django 1.7 URL映射

[英]Django 1.7 URLs Mapping

I'm getting a behavior that's really not making sense to me regarding the urls in my django project. 对于django项目中的网址,我遇到的行为对我来说真的没有任何意义。 This isn't my first django project, so I'm sure it's something stupid, but I'm on day 2, and whatever it is, I can't find it. 这不是我的第一个django项目,所以我确定这是一个愚蠢的事情,但是我现在已经是第2天了,无论如何,我都找不到它。

I have a project vote . 我有一个项目投票 In vote/urls.py : 表决/urls.py中

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

urlpatterns = patterns('',
    url(r'^users/', include('users.urls')),
    url(r'^manage/', include(admin.site.urls)),
)

Within the project, I have an app users , I have the file users/urls.py : 在项目中,我有一个应用程序用户 ,我有一个文件users / urls.py

from django.conf.urls import patterns, url
from rest_framework.urlpatterns import format_suffix_patterns

from users import services

urlpatterns = patterns(
    url(r'^register/$', services.RegisterUser.as_view()),
)

Yet, when I runserver and navigate to localhost:8000/users/register/ I get a 404 error: 但是,当我运行服务器并导航到localhost:8000 / users / register /时,出现404错误:

Using the URLconf defined in wevote.urls, Django tried these URL patterns, in this order:
^manage/
The current URL, users/register/, didn't match any of these.

For some reason, it's not pulling in the users.urls, and I can't figure out why. 出于某种原因,它没有引入users.urls,我也不知道为什么。 I have both 'users' and 'rest_framework' in INSTALLED_APPS. 我在INSTALLED_APPS中同时拥有“用户”和“ rest_framework”。 Any help would be appreciated. 任何帮助,将不胜感激。

Additional information: From settings.py: 附加信息:从settings.py:

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    'rest_framework',
    'ujson',

    'analytics',
    'elections',
    'offices',
    'users'
)

Also, the project structure: 另外,项目结构:

vote 投票

  • analytics 分析
  • elections 选举
  • offices 办事处
  • users 用户
    • urls.py urls.py
    • ... ...
  • vote 投票
    • settings.py settings.py
    • urls.py urls.py
    • ... ...
  • manage.py manage.py
  • requirements.txt requirements.txt

I believe you are missing the prefix (the first positional argument) in your call to patterns in users/urls.py . 我相信您在对users/urls.py patterns的调用中缺少前缀(第一个位置参数)。 Try adding it: 尝试添加它:

from django.conf.urls import patterns, url
from rest_framework.urlpatterns import format_suffix_patterns

from users import services

urlpatterns = patterns('',
    url(r'^register/$', services.RegisterUser.as_view()),
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM