2017-08-08 65 views
1

我是新來的django,所以我跟着書,我試圖執行Django AllAuth後,將正確的代碼放在適當的位置,當我試圖運行服務器時出現錯誤。整個項目工作正常,直到我在項目中實施了全面的解決方案。下面是從終端我的錯誤,我的settings.pypython django allauth終端錯誤

錯誤

Traceback (most recent call last): 
    File "manage.py", line 22, in <module> 
    execute_from_command_line(sys.argv) 
    File "/Users/Olar/Desktop/tryTen/lib/python2.7/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line 
    utility.execute() 
    File "/Users/Olar/Desktop/tryTen/lib/python2.7/site-packages/django/core/management/__init__.py", line 307, in execute 
    settings.INSTALLED_APPS 
    File "/Users/Olar/Desktop/tryTen/lib/python2.7/site-packages/django/conf/__init__.py", line 56, in __getattr__ 
    self._setup(name) 
    File "/Users/Olar/Desktop/tryTen/lib/python2.7/site-packages/django/conf/__init__.py", line 41, in _setup 
    self._wrapped = Settings(settings_module) 
    File "/Users/Olar/Desktop/tryTen/lib/python2.7/site-packages/django/conf/__init__.py", line 110, in __init__ 
    mod = importlib.import_module(self.SETTINGS_MODULE) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module 
    __import__(name) 
    File "/Users/Olar/Desktop/tryTen/src/tryTen/settings.py", line 164 
SyntaxError: Non-ASCII character '\xe2' in file /Users/Olar/Desktop/tryTen/src/tryTen/settings.py on line 164, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details 

Settings.py

""" 
Django settings for tryTen project. 

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

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

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

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__))) 

EMAIL_HOST = 'smtp.gmail.com' 
EMAIL_HOST_USER = '[email protected]' 
EMAIL_HOST_PASSWORD = 'damilola007' 
EMAIL_PORT = '587' 
EMAIL_USE_TLS = True 

# 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 = 'tmujhqxuqkgm)3n%[email protected]*_((hxnwlg7b)ubwjbb9c&ep' 

# 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', 
    'ctrybe', 
    'contact', 
    'crispy_forms', 
    # The following apps are required: 
    'django.contrib.auth', 
    'django.contrib.sites', 
    'allauth', 
    'allauth.account', 
    'allauth.socialaccount', 
    # ... include the providers you want to enable: 
] 

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 = 'tryTen.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', 
      ], 
     }, 
    }, 
] 

AUTHENTICATION_BACKENDS = (

    # Needed to login by username in Django admin, regardless of `allauth` 
    'django.contrib.auth.backends.ModelBackend', 

    # `allauth` specific authentication methods, such as login by e-mail 
    'allauth.account.auth_backends.AuthenticationBackend', 

) 



WSGI_APPLICATION = 'tryTen.wsgi.application' 


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

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


# 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/' 

if DEBUG: 
    MEDIA_URL = '/media/' 
    STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static", "static-only") 
    MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static", "media") 
    STATICFILES_DIRS = (
    os.path.join(os.path.dirname(BASE_DIR), "static", "static"), 
) 

CRISPY_TEMPLATE_PACK = 'bootstrap4' 

SITE_ID = 1 

LOGIN_URL = '/accounts/login' 
LOGIN_REDIRECT_URL = '/' 

ACCOUNT_AUTHENTICATION_METHOD = 「username_email」 
ACCOUNT_CONFIRM_EMAIL_ON_GET =False 
ACCOUNT_EMAIL_CONFIRMATION_ANONYMOUS_REDIRECT_URL =LOGIN_URL 
ACCOUNT_EMAIL_CONFIRMATION_AUTHENTICATED_REDIRECT_URL =None 


ACCOUNT_EMAIL_CONFIRMATION_EXPIRE_DAYS =3 
ACCOUNT_EMAIL_CONFIRMATION_HMAC =True 
ACCOUNT_EMAIL_REQUIRED =False 
ACCOUNT_EMAIL_VERIFICATION =None 
ACCOUNT_EMAIL_SUBJECT_PREFIX =」My subject: 」 
ACCOUNT_DEFAULT_HTTP_PROTOCOL =」http」 

ACCOUNT_LOGOUT_ON_GET =False 
ACCOUNT_LOGOUT_REDIRECT_URL =」/」 
ACCOUNT_SIGNUP_FORM_CLASS =None 
ACCOUNT_SIGNUP_PASSWORD_ENTER_TWICE =True 
ACCOUNT_UNIQUE_EMAIL =True 
ACCOUNT_USER_MODEL_EMAIL_FIELD =」email」 
ACCOUNT_USER_MODEL_USERNAME_FIELD =」username」 


ACCOUNT_USERNAME_MIN_LENGTH =3 
ACCOUNT_USERNAME_REQUIRED =True 
ACCOUNT_USERNAME_BLACKLIST =[] 
ACCOUNT_PASSWORD_INPUT_RENDER_VALUE =False 
ACCOUNT_PASSWORD_MIN_LENGTH = 6 
ACCOUNT_LOGIN_ON_EMAIL_CONFIRMATION =True 

我正在運行的Python 3.5 *我編輯了問題包括我的settings.py *在此先感謝

+0

for_user = 1&IS_ACTIVE = 1,這不是我的代碼 – King

+0

你是怎麼修理它? – King

+0

顯示你的'settings.py' –

回答

2

更換所有"例如

老:

ACCOUNT_AUTHENTICATION_METHOD = 「username_email」 
#        ^^^   ^^^ 

ACCOUNT_AUTHENTICATION_METHOD = "username_email" 
#        ^^^   ^^^ 
+0

謝謝。它修復了它 – King

2

在線路164

ACCOUNT_AUTHENTICATION_METHOD = 「username_email」 

看來你使用了不同的報價市場上贏得這裏:

「」

這可能會導致錯誤。試着用

'來代替你的報價市場上贏得

「」