Python django-urlpatterns为已定义的URL提供404错误

Python django-urlpatterns为已定义的URL提供404错误,python,django,django-rest-framework,Python,Django,Django Rest Framework,我有一个在django上运行的应用程序。但我得到一些URL的错误代码404,即使这些URL已经定义 from .views import check_secret_key # a function in views.py from .swagger_schema import SwaggerSchemaView # a class inheriting APIView from .kom.kom_writer import kom_status

我有一个在django上运行的应用程序。但我得到一些URL的错误代码404,即使这些URL已经定义

from .views import check_secret_key                 # a function in views.py
from .swagger_schema import SwaggerSchemaView       # a class inheriting APIView
from .kom.kom_writer import kom_status              # a function
from django.conf.urls import url


urlpatterns = [
    url(r'^docs/api-docs/', SwaggerSchemaView.as_view()),
    url(r'^nag/secret-key/', check_secret_key),
    url(r'^nag/kom-status/', kom_status),
]
API
curlhttp://localhost:9999/internal/docs/api-docs/
工作正常,但
curlhttp://localhost:9999/internal/nag/kom-状态/
nag/密钥
fir 404错误

未找到在此服务器上未找到请求的资源

我不知道我错过了什么

注意:应用程序最近从DJango 1.8更新为1.11,djangorestframework 3.2.5更新为3.5.3。在此之前,它运行良好

出于调试目的,我现在只返回成功响应

from django.http import HttpResponse

def check_secret_key(request):
    r = HttpResponse("I am good", content_type='text/plain', status=200)
    return r

你的定义应该是

urlpatterns=[
url(r'.*docs/api docs/',SwaggerSchemaView.as_view()),
url(r'.*nag/secret key/',检查密钥),
url(r.*nag/kom status/,kom_status),
]

您还需要提供
/internal
url定义。

我发现了这个问题。应用程序正在使用两个wsgi.py来运行django应用程序

两个wsgi.py文件都在使用

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "it.settings.prod")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "nt.settings.prod")
改成

os.environ["DJANGO_SETTINGS_MODULE"] = "it.settings.prod"
os.environ["DJANGO_SETTINGS_MODULE"] = "nt.settings.prod"
解决了这个问题


参考

您是否也可以发布相应的视图?一个原因可能是您的视图使用404代码进行响应。
/internal
从何而来,因为它没有在模式中定义?