找不到404页面Django

时间:2017-08-11 14:21:27

标签: python django web

昨天我正在研究我的django项目并且工作得很好,但今天当我运行服务器并尝试访问我的页面时,它无效。

错误消息:

Page not found (404)
Request Method: GET
Request URL:    http://127.0.0.1:8000/Oraculum_Data/cancerColo/

Using the URLconf defined in Oraculum.urls, Django tried these URL patterns, in this order:
^admin/
^Oraculum_Data/ ^$
^Oraculum_Data/ ^Oraculum_Data/login/$
^Oraculum_Data/ ^Oraculum_Data/cancerColo/$
^Oraculum_Data/ ^Oraculum_Data/api/data/$
^Oraculum_Data/ ^Oraculum_Data/api/chart/data/$
The current path, Oraculum_Data/cancerColo/, didn't match any of these.

我的网址模式:

urlpatterns = [
    url(r'^admin/', include('Oraculum_Data.urls')),
    url(r'^Oraculum_Data/', include('Oraculum_Data.urls'))
]

我在Oraculum_Data app中的网址模式:

from django.conf.urls import url
from . import views
from django.contrib.auth.views import login



    urlpatterns = [
        url(r'^$', views.home),
        url(r'^Oraculum_Data/login/$', login, {'template_name': 'Oraculum_Data/login.html'}),
        url(r'^Oraculum_Data/cancerColo/$', views.cancerColo),
        url(r'^Oraculum_Data/api/data/$', views.get_data),
        url(r'^Oraculum_Data/api/chart/data/$', views.ChartData.as_view()),
    ]

我的Oraculum_Data app views.py文件:

from django.http import JsonResponse
from django.shortcuts import render, HttpResponse
import requests
import pandas as pd

from rest_framework.views import APIView
from rest_framework.response import Response

def home(request):
    name = "Test name"

    args = {'MyName' : name}
    return render(request, 'Pages/HomePage.html', args)

def cancerColo(request):
    response = requests.get('http://sage.saude.gov.br/graficos/cancerMamaColo/cancerColo3544.php?output=json')
    response_json = response.json()
    df = pd.DataFrame(response_json['resultset'], columns=['Ano', 'Branca', 'Amarela', 'Ignorada', 'Indigena', 'Parda', 'Preta'])
    args = {'dataframe' : df.to_html(classes="table table-striped"), 'name' : 'Câncer de colo de útero (por raça)'}
    return render(request, 'Pages/CancerColo.html', args)

def get_data(request, *args, **kwargs):
    data = {
        "sales" : 100,
        "customers" : 10,
    } 
    return JsonResponse(data) # http response   

class ChartData(APIView):
    authentication_classes = []
    permission_classes = []

    def get(self, request, format=None):
        """
        Return a list of all users.
        """
        data = {
        "sales" : 100,
        "customers" : 10,
        } 
        return Response(data)

设置:

INSTALLED_APPS = [
    'rest_framework',
    'Oraculum_Data',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

主页仍然正常,但其他人没有。

代码有问题吗?它昨天正在运作。

0 个答案:

没有答案