Python django.core.exceptions.ImpropertlyConfigured:“不正确配置”^(?$”不是有效的正则表达式:模式意外结束
每次我尝试运行我的站点时,我都会收到标题错误。 全文如下:Python django.core.exceptions.ImpropertlyConfigured:“不正确配置”^(?$”不是有效的正则表达式:模式意外结束,python,django,django-urls,Python,Django,Django Urls,每次我尝试运行我的站点时,我都会收到标题错误。 全文如下: Performing system checks... Unhandled exception in thread started by <function wrapper at 0x101c5bcf8> Traceback (most recent call last): File "/Users/student/ENV/lib/python2.7/site-packages/django/utils/autorel
Performing system checks...
Unhandled exception in thread started by <function wrapper at 0x101c5bcf8>
Traceback (most recent call last):
File "/Users/student/ENV/lib/python2.7/site-packages/django/utils/autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "/Users/student/ENV/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 124, in inner_run
self.check(display_num_errors=True)
File "/Users/student/ENV/lib/python2.7/site-packages/django/core/management/base.py", line 359, in check
include_deployment_checks=include_deployment_checks,
File "/Users/student/ENV/lib/python2.7/site-packages/django/core/management/base.py", line 346, in _run_checks
return checks.run_checks(**kwargs)
File "/Users/student/ENV/lib/python2.7/site-packages/django/core/checks/registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "/Users/student/ENV/lib/python2.7/site-packages/django/core/checks/urls.py", line 16, in check_url_config
return check_resolver(resolver)
File "/Users/student/ENV/lib/python2.7/site-packages/django/core/checks/urls.py", line 26, in check_resolver
return check_method()
File "/Users/student/ENV/lib/python2.7/site-packages/django/urls/resolvers.py", line 255, in check
warnings.extend(check_resolver(pattern))
File "/Users/student/ENV/lib/python2.7/site-packages/django/core/checks/urls.py", line 26, in check_resolver
return check_method()
File "/Users/student/ENV/lib/python2.7/site-packages/django/urls/resolvers.py", line 172, in check
warnings = self._check_pattern_startswith_slash()
File "/Users/student/ENV/lib/python2.7/site-packages/django/urls/resolvers.py", line 140, in _check_pattern_startswith_slash
regex_pattern = self.regex.pattern
File "/Users/student/ENV/lib/python2.7/site-packages/django/urls/resolvers.py", line 93, in __get__
instance.__dict__['regex'] = self._compile(instance._regex)
File "/Users/student/ENV/lib/python2.7/site-packages/django/urls/resolvers.py", line 109, in _compile
(regex, six.text_type(e))
django.core.exceptions.ImproperlyConfigured: "^(?$" is not a valid regular expression: unexpected end of pattern
我还检查了我的settings.py,因为它有点乱,但没有用
import os
# 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/1.11/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'y@rn-kswhu)c@ae@)-s952xdfxb_)7yswq+pvm+63*n8i89^2d'
# 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',
'django.contrib.sites',
'data.apps.DataConfig',
]
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',
]
ROOT_URLCONF = 'icecubesite.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 = 'icecubesite.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'icecube',
'USER': 'root',
'PASSWORD': 'NewPassword',
'HOST': '',
'PORT': ''
}
}
# Password validation
# https://docs.djangoproject.com/en/1.11/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/1.11/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.11/howto/static-files/
STATIC_URL = '/static/'
Views.py
from __future__ import unicode_literals
from django.shortcuts import get_object_or_404, render
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.views import generic
from django.http import HttpResponse
from django.shortcuts import render
from .models import Cubedata
# Test index
#hey, this is a table containing just like at entire database as an object.
def table(request):
tables = Cubedata.objects.all()
template_name = "data/table.html"
data = {
'tables' : tables ,
}
return render_to_response (template, data,
context_instance = RequestContext( request ))
我真的认为我的错误在于我有意大利面代码,但是我真的不确定这个错误是从哪里来的。我在代码中的任何地方都找不到它;我已经对它进行了多次梳理。如果需要的话,我会发布我所有的文件,但我发布的文件最有可能出错。问题在于正则表达式。”^(?$”,您必须更正它 您期望该正则表达式的行为是什么
(添加到对匹配项进行分组中,但括号未闭合。如果在**/URL.py中的任何位置都找不到表达式
r'^(?$'
),则它很可能不在那里
r'^(?$'
潜伏的第二个最好的地方是你的*.pyc文件。它们往往被遗忘,在极少数情况下会引起极大的头痛。只要把它们扔掉,很可能r'^(?$'
也会消失
希望这有助于愉快地编码!请用有关如何更正的信息扩展您的答案?我不确定如何更正,我在代码中的任何地方都找不到该片段,我已经梳理了我所有的文件。在这之后您没有其他
URL模式吗?不,这是我的整个URL.py文件,我没有其他模式。我应该有m吗ore?没有,只是因为我看到那里的一切都是正确的,除了你有url('data/',views.data)
,它应该以^
url('^data/',views.data)开头
啊,我的错,谢谢!我本来就有这个问题,我一定是忘了在之前处理我的url.py文件时添加^s来解决这个问题。我已经解决了这个问题,但仍然存在同样的问题。我无法确定这里出了什么问题,请尝试将这个url(r'^$,views.IndexView.as_view(),name='index'),
更改为url(r“^index/$”,views.IndexView.as_view(),name='index'),“
只是想看看您是否仍然会遇到这个问题
from __future__ import unicode_literals
from django.shortcuts import get_object_or_404, render
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.views import generic
from django.http import HttpResponse
from django.shortcuts import render
from .models import Cubedata
# Test index
#hey, this is a table containing just like at entire database as an object.
def table(request):
tables = Cubedata.objects.all()
template_name = "data/table.html"
data = {
'tables' : tables ,
}
return render_to_response (template, data,
context_instance = RequestContext( request ))