2016-11-20 58 views
0

時,遇到了一個404錯誤我得到的錯誤:運行我的Django的服務器站點

找不到網頁(404) 請求方法:GET 請求URL:http://localhost:8001/ 使用URL配置在recipe_organizer.urls定義,Django的按以下順序嘗試了這些網址格式: ^ admin/ ^ recipe/ ^ media /(?P。*)$ 當前的URL與這些網址中的任何一個都不匹配。

這是工作不久前,但沒有什麼會發布。

這裏是我的urls.py文件:

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

urlpatterns = [ 
    url(r'^admin/', include(admin.site.urls)), 
    url(r'^recipes/', include('apps.recipes.urls')), 
    url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}), 
] 

這裏是我的設置(不包括特殊鍵包括):

""" 
Django settings for recipe_organizer project. 

Generated by 'django-admin startproject' using Django 1.8. 

For more information on this file, see 
https://docs.djangoproject.com/en/1.8/topics/settings/ 

For the full list of settings and their values, see 
https://docs.djangoproject.com/en/1.8/ref/settings/ 
""" 

# Build paths inside the project like this: os.path.join(BASE_DIR, ...) 
import os 

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 


# Quick-start development settings - unsuitable for production 
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/ 

# SECURITY WARNING: keep the secret key used in production secret! 
SECRET_KEY = '-------------------------------------' 

# SECURITY WARNING: don't run with debug turned on in production! 
DEBUG = True 

ALLOWED_HOSTS = [] 


# Application definition 

INSTALLED_APPS = (
    'django.contrib.admin', 
    'django.contrib.auth', 
    'django.contrib.contenttypes', 
    'django.contrib.sessions', 
    'django.contrib.messages', 
    'django.contrib.staticfiles', 
    'apps.recipes', 
    'rest_framework', 
    'corsheaders', 
) 

MIDDLEWARE_CLASSES = (
    'corsheaders.middleware.CorsMiddleware', 
    'django.contrib.sessions.middleware.SessionMiddleware', 
    'django.middleware.common.CommonMiddleware', 
    'django.middleware.csrf.CsrfViewMiddleware', 
    'django.contrib.auth.middleware.AuthenticationMiddleware', 
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 
    'django.contrib.messages.middleware.MessageMiddleware', 
    'django.middleware.clickjacking.XFrameOptionsMiddleware', 
    'django.middleware.security.SecurityMiddleware', 
) 

ROOT_URLCONF = 'recipe_organizer.urls' 

TEMPLATES = [ 
    { 
     'BACKEND': 'django.template.backends.django.DjangoTemplates', 
     'DIRS': [], 
     'APP_DIRS': True, 
     'OPTIONS': { 
      'context_processors': [ 
       'django.template.context_processors.debug', 
       'django.template.context_processors.request', 
       'django.contrib.auth.context_processors.auth', 
       'django.contrib.messages.context_processors.messages', 
      ], 
     }, 
    }, 
] 

WSGI_APPLICATION = 'recipe_organizer.wsgi.application' 


# Database 
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases 

DATABASES = { 
    'default': { 
     'ENGINE': 'django.db.backends.sqlite3', 
     'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 
    } 
} 


# Internationalization 
# https://docs.djangoproject.com/en/1.8/topics/i18n/ 

LANGUAGE_CODE = 'en-us' 

TIME_ZONE = 'UTC' 

USE_I18N = True 

USE_L10N = True 

USE_TZ = True 


# Static files (CSS, JavaScript, Images) 
# https://docs.djangoproject.com/en/1.8/howto/static-files/ 

MEDIA_ROOT = BASE_DIR + '/apps/recipes/media' 

MEDIA_URL = '/media/' 

STATIC_ROOT = 'static' 

STATIC_URL = '/static/' 

CORS_ORIGIN_WHITELIST = (
    'localhost:8000', 
    'localhost/', 
) 


CORS_ORIGIN_ALLOW_ALL = True 

最後,這裏是我的manage.py文件:

#!/usr/bin/env python 
import os 
import sys 

if __name__ == "__main__": 
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "recipe_organizer.settings") 

    from django.core.management import execute_from_command_line 

    execute_from_command_line(sys.argv) 

有沒有人有任何想法?這將非常感激。

回答

1

您能訪問http://localhost:8001/admin/嗎?

如果是的話,那麼問題只是在於,你還沒有定義爲根的URL項http://localhost:8001/

喜歡的東西:

URL(R '^ $',views.index,名稱= '索引'),

應該做的伎倆。

不要忘記在views.py中定義索引

+0

請問您可以更好地格式化它嗎?我嘗試編輯,但沒有足夠的編輯所以stackoverflow不允許我爲你編輯它。 – Aditya

相關問題