由于某种原因,我有一个无效的网址。我得到了404,“找不到'新'”。这是我的urls.py:
url(r'^assets/new', 'watershed.views.new_asset', name='new_asset'),
我的urls.py还有很多内容,但这只是其中包含“资产”这个词的唯一内容。如果我将此网址更改为任何/ new,则可行。如果我拼错资产(assettss / new),它就有效。如果我拿出/ new并且只使用“资产”,它也可以正常工作。在我的views文件夹中,我有一个__ init __.py,其中包含以下内容:
from groups import *
from members import *
from leave_group import *
from payments import *
from assets import *
我还有一个assets.py,其中包含以下内容:
from django.contrib.auth.decorators import login_required
from watershed.models import Member, Org, OrgToMember, Asset
from django.shortcuts import render, redirect
from django.contrib.auth.models import User
def new_asset(request):
return render(request, 'asset_add.html')
我不知道Django对资产/新资产不喜欢什么。
更新:这是我的完整urls.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
url(r'^', include('outside.urls')),
url(r'^blog', include('blog.urls')),
url(r'^admin', include(admin.site.urls)),
url(r'^logout', 'watershed.views.logout', name='logout'),
url(r'^register/create', 'watershed.views.create', name='create'),
url(r'^register', 'watershed.views.register', name='register'),
url(r'^translog/(\d+)', 'watershed.views.translog', name='translog'),
url(r'^settings', 'watershed.views.settings', name='settings'),
# Group URIs
url(r'^groups/(\d+)/leave', 'watershed.views.leave_group', name='leave_group'),
url(r'^groups/(\d+)/dissolve', 'watershed.views.dissolve_group', name='dissolve_group'),
url(r'^groups/new', 'watershed.views.add_group_form', name='add_group_form'),
url(r'^groups/(\d+)', 'watershed.views.dashboard', name='dashboard'),
url(r'^groups/add', 'watershed.views.add_group', name='add_group'),
url(r'^groups', 'watershed.views.groups', name='groups'),
# Member URIs
url(r'^members/(\d+)', 'watershed.views.profile', name='profile'),
url(r'^member/login', 'watershed.views.login', name='login'),
# Payments URIs
url(r'^payments', 'watershed.views.payments', name='payments'),
# Asset URIs
url(r'^assets/new', 'watershed.views.new_asset', name='new_asset'),
答案 0 :(得分:0)
您new_assets
函数包含assets.py
文件,但您从views.py
文件导入此函数。使用此:
url(r'^assets/new', 'path.to.assets.new_asset', name='new_asset'),
答案 1 :(得分:0)
我明白了。问题是我的settings.py中的静态网址是 - 等待它:
STATIC_URL = '/assets/'
所以,显然,其中一个必须改变。