错误问题*发生服务器错误。请与管理员联系* django rest框架

时间:2020-07-05 02:24:23

标签: django-rest-framework backend django-urls django-settings

我正在尝试测试一些基本的后备功能,但似乎出现此错误发生服务器错误。尝试连接到本地主机http://127.0.0.1:8000http://127.0.0.1:8000/sise/时,请联系管理员

起初,我出现此错误,显示 django.core.exceptions.ImproperlyConfigured:包含的URLconf'Dashboard_sise.urls'似乎没有任何模式。如果您在文件中看到有效的模式,则说明问题可能是由循环导入引起的。,但是在我在设置文件 ROOT_URLCONF ='Dashboard_sise.urls'中注释了这一行之后,错误发生了变化进入服务器错误。请联系管理员

任何人都可以帮我解决这个问题,我已经尝试过更改urls.py文件中的urlpatterns,但是它不起作用,我还尝试了操作设置文件中的MIDDLEWARE部分,但是没有任何改变。

这是Dashboard_sise.urls代码

from django.contrib import admin
from django.urls import include, path

urlpatterns = [
    path('admin/', admin.sites.urls),
    path('sise/', include('Dashboard.urls')),
]

这是Dashboard.urls代码

from rest_framework.routers import DefaultRouter
from Dashboard.views import *

router = DefaultRouter()

router.register(r'accee', AcceeViewSet, basename='accee')
router.register(r'rapport', RapportViewSet, basename='rapport')
router.register(r'prise_fonction', PointageUtilisateurViewSet, basename='prise_fonction')

urlPatterns = router.urls

最后是设置文件


# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
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/3.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '+f-@$j*(-8^*7ijk@6_hpki@)am4e%na6ttp)54@-ddcs0#fgy'

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

ALLOWED_HOSTS = ['*']
PREPEND_WWW = False

# Application definition

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

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'corsheaders.middleware.CorsMiddleware',
]


TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')]
        ,
        '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 = 'Dashboard_sise.wsgi.application'

'''ROOT_URLCONF = 'Dashboard_sise.urls'''


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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'MainCourante',
        'USER': 'postgres',
        'PASSWORD': 'root',
        'HOST': 'localhost',
        'PORT': '5432',
    }
}


# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


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

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

APPEND_SLASH = False


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

STATIC_URL = '/static/'


'''REST_FRAMEWORK = {
    'DEFAULT_RENDERER_CLASSES': (
        'rest_framework.renderers.JSONRenderer',
        'rest_framework.authentification.BasicAuthentification'
        'rest_framework.authentification.SessionAuthentification'
        # 'rest_framework.permissions.IsAuthentificated'
        # 'rest_framework.permissions.AllowAny'
    )
}'''

        
CORS_ORIGIN_ALLOW_ALL = True  # If this is used then `CORS_ORIGIN_WHITELIST` will not have any effect

感谢您的光临

2 个答案:

答案 0 :(得分:1)

如果有人遇到相同的错误,我会回答。我的数据库结构有问题..在models.py文件中实现的模型与创建的数据库不匹配,因此它一直向我显示此错误...一旦修复了models.py文件,一切都很好/ p>

答案 1 :(得分:0)

也许是原因。

urlPatterns = router.urls

通常为urlpatterns