django值错误:int()的基数为10的文字无效

时间:2016-02-28 08:12:44

标签: python django rest django-rest-framework

我正在从教程中学习djangorest框架,并坚持与授权和权限相关的第四个主题。

我收到了一个值错误,即

invalid literal for int() with base 10: 'owner_id'

我认为这与下面的models.py文件中Snippet模型中的所有者列有关

from django.db import models
from pygments.lexers import get_all_lexers, get_lexer_by_name
from pygments.styles import get_all_styles
from pygments import highlight
from pygments.formatters.html import HtmlFormatter



LEXERS = [item for item in get_all_lexers() if item[1]]
LANGUAGE_CHOICES = sorted([(item[1][0], item[0]) for item in LEXERS])
STYLE_CHOICES = sorted((item, item) for item in get_all_styles())

# Create your models here.

class Snippet(models.Model):
    created = models.DateTimeField(auto_now_add = True)
    title = models.CharField(max_length = 100, blank = True, default = '')
    code = models.TextField(default = '')
    linenos = models.BooleanField(default = False)
    language = models.CharField(choices = LANGUAGE_CHOICES, default = "Python", max_length = 100)
    style = models.CharField(choices=STYLE_CHOICES, default='friendly', max_length=100)
    owner = models.ForeignKey('auth.User', related_name = "snippets")
    highlighted = models.TextField(default = "")

    class Meta:
        ordering = ('created',)

    def save(self, *args, **kwargs):
        """
        Use the `pygments` library to create a highlighted HTML
        representation of the code snippet.
        """
        lexer = get_lexer_by_name(self.language)
        linenos = self.linenos and 'table' or False
        options = self.title and {'title': self.title} or {}
        formatter = HtmlFormatter(style=self.style, linenos=linenos,
                                  full=True, **options)
        self.highlighted = highlight(self.code, lexer, formatter)
        super(Snippet, self).save(*args, **kwargs)

另外,找到views.py

from snippets.models import *
from snippets.serializers import *
from rest_framework import generics
from rest_framework import permissions

class SnippetList(generics.ListCreateAPIView):
    queryset = Snippet.objects.all()
    serializer_class = SnippetSerializer
    permission_classes = (permissions.IsAuthenticatedOrReadOnly,)

    def perform_create(self, serializer):
        serializer.save(owner = self.request.user)

class SnippetDetail(generics.RetrieveUpdateDestroyAPIView):
    queryset = Snippet.objects.all()
    serializer_class = SnippetSerializer
    permission_classes = (permissions.IsAuthenticatedOrReadOnly,)

class UserList(generics.ListAPIView):
    queryset = Snippet.objects.all()
    serializer_class = SnippetSerializer

class UserDetail(generics.RetrieveAPIView):
    queryset = Snippet.objects.all()
    serializer_class = SnippetSerializer

serializers.py

from rest_framework import serializers
from snippets.models import *
from django.contrib.auth.models  import User

class SnippetSerializer(serializers.Serializer):
    pk = serializers.IntegerField(read_only = True)
    title = serializers.CharField(required = False, allow_blank = True, max_length = 100)
    code = serializers.CharField(style = {"base_template":"textarea.html"})
    linenos = serializers.BooleanField(required = False)
    language = serializers.ChoiceField(choices = LANGUAGE_CHOICES, default = 'Python')
    style = serializers.ChoiceField(choices=STYLE_CHOICES, default='friendly')
    owner = serializers.ReadOnlyField(source='owner.username')

    def create(self, validated_data):
        return Snippet.objects.create(**validated_data)

    def update(self, instance, validated_data):
        instance.title = validated_data.get('title', instance.title)
        instance.code = validated_data.get('code', instance.code)
        instance.linenos = validated_data.get('linenos', instance.linenos)
        instance.language = validated_data.get('language', instance.language)
        instance.style = validated_data.get('codstylee', instance.style)
        instance.save()
        return instance


class UserSerializer(serializers.ModelSerializer):
    snippets = serializers.PrimaryKeyRelatedField(many = True, queryset = Snippet.objects.all())

    class Meta:
        model = User
        fields = {"id", "username", "snippets"}

和urls.py

from django.conf.urls import url
from snippets import views
from rest_framework.urlpatterns import format_suffix_patterns

urlpatterns = [
    url(r'^snippets/$', views.SnippetList.as_view()),
    url(r'^snippets/(?P<pk>[0-9]+)/$', views.SnippetDetail.as_view()),
    url(r'^users/$', views.UserList.as_view()),
    url(r'^users/(?P<pk>[0-9]+)/$', views.UserDetail.as_view()),
]

urlpatterns = format_suffix_patterns(urlpatterns)

错误说明: -

ValueError at /snippets/
invalid literal for int() with base 10: 'owner_id'
Request Method: GET
Request URL:    http://127.0.0.1:8000/snippets/
Django Version: 1.9.2
Exception Type: ValueError
Exception Value:    
invalid literal for int() with base 10: 'owner_id'
Exception Location: E:\norestdjangorest\env1\lib\site-packages\django\db\models\fields\__init__.py in get_prep_value, line 976
Python Executable:  E:\norestdjangorest\env1\Scripts\python.exe
Python Version: 3.4.3
Python Path:    
['e:\\norestdjangorest\\tutorial',
 'C:\\Windows\\system32\\python34.zip',
 'E:\\norestdjangorest\\env1\\DLLs',
 'E:\\norestdjangorest\\env1\\lib',
 'E:\\norestdjangorest\\env1\\Scripts',
 'C:\\Python34\\Lib',
 'C:\\Python34\\DLLs',
 'E:\\norestdjangorest\\env1',
 'E:\\norestdjangorest\\env1\\lib\\site-packages']
Server time:    Sun, 28 Feb 2016 12:57:18 +0530
Traceback Switch to copy-and-paste view

E:\norestdjangorest\env1\lib\site-packages\django\db\models\fields\related_descriptors.py in __get__
            rel_obj = getattr(instance, self.cache_name) ...
▶ Local vars
During handling of the above exception ('Snippet' object has no attribute '_owner_cache'), another exception occurred:
E:\norestdjangorest\env1\lib\site-packages\django\core\handlers\base.py in get_response
                    response = self.process_exception_by_middleware(e, request) ...
▶ Local vars
E:\norestdjangorest\env1\lib\site-packages\django\core\handlers\base.py in get_response
                    response = wrapped_callback(request, *callback_args, **callback_kwargs) ...
▶ Local vars
E:\norestdjangorest\env1\lib\site-packages\django\views\decorators\csrf.py in wrapped_view
        return view_func(*args, **kwargs) ...
▶ Local vars
E:\norestdjangorest\env1\lib\site-packages\django\views\generic\base.py in view
            return self.dispatch(request, *args, **kwargs) ...
▶ Local vars
E:\norestdjangorest\env1\lib\site-packages\rest_framework\views.py in dispatch
            response = self.handle_exception(exc) ...
▶ Local vars
E:\norestdjangorest\env1\lib\site-packages\rest_framework\views.py in dispatch
            response = handler(request, *args, **kwargs) ...
▶ Local vars
E:\norestdjangorest\env1\lib\site-packages\rest_framework\generics.py in get
        return self.list(request, *args, **kwargs) ...
▶ Local vars
E:\norestdjangorest\env1\lib\site-packages\rest_framework\mixins.py in list
        return Response(serializer.data) ...
▶ Local vars
E:\norestdjangorest\env1\lib\site-packages\rest_framework\serializers.py in data
        ret = super(ListSerializer, self).data ...
▶ Local vars
E:\norestdjangorest\env1\lib\site-packages\rest_framework\serializers.py in data
                self._data = self.to_representation(self.instance) ...
▶ Local vars
E:\norestdjangorest\env1\lib\site-packages\rest_framework\serializers.py in to_representation
            self.child.to_representation(item) for item in iterable ...
▶ Local vars
E:\norestdjangorest\env1\lib\site-packages\rest_framework\serializers.py in <listcomp>
            self.child.to_representation(item) for item in iterable ...
▶ Local vars
E:\norestdjangorest\env1\lib\site-packages\rest_framework\serializers.py in to_representation
                attribute = field.get_attribute(instance) ...
▶ Local vars
E:\norestdjangorest\env1\lib\site-packages\rest_framework\fields.py in get_attribute
            return get_attribute(instance, self.source_attrs) ...
▶ Local vars
E:\norestdjangorest\env1\lib\site-packages\rest_framework\fields.py in get_attribute
                instance = getattr(instance, attr) ...
▶ Local vars
E:\norestdjangorest\env1\lib\site-packages\django\db\models\fields\related_descriptors.py in __get__
                qs = qs.filter(**self.field.get_reverse_related_filter(instance)) ...
▶ Local vars
E:\norestdjangorest\env1\lib\site-packages\django\db\models\query.py in filter
        return self._filter_or_exclude(False, *args, **kwargs) ...
▶ Local vars
E:\norestdjangorest\env1\lib\site-packages\django\db\models\query.py in _filter_or_exclude
            clone.query.add_q(Q(*args, **kwargs)) ...
▶ Local vars
E:\norestdjangorest\env1\lib\site-packages\django\db\models\sql\query.py in add_q
        clause, _ = self._add_q(q_object, self.used_aliases) ...
▶ Local vars
E:\norestdjangorest\env1\lib\site-packages\django\db\models\sql\query.py in _add_q
                    allow_joins=allow_joins, split_subq=split_subq, ...
▶ Local vars
E:\norestdjangorest\env1\lib\site-packages\django\db\models\sql\query.py in build_filter
            condition = self.build_lookup(lookups, col, value) ...
▶ Local vars
E:\norestdjangorest\env1\lib\site-packages\django\db\models\sql\query.py in build_lookup
                return final_lookup(lhs, rhs) ...
▶ Local vars
E:\norestdjangorest\env1\lib\site-packages\django\db\models\lookups.py in __init__
        self.rhs = self.get_prep_lookup() ...
▶ Local vars
E:\norestdjangorest\env1\lib\site-packages\django\db\models\lookups.py in get_prep_lookup
        return self.lhs.output_field.get_prep_lookup(self.lookup_name, self.rhs) ...
▶ Local vars
E:\norestdjangorest\env1\lib\site-packages\django\db\models\fields\__init__.py in get_prep_lookup
            return self.get_prep_value(value) ...
▶ Local vars
E:\norestdjangorest\env1\lib\site-packages\django\db\models\fields\__init__.py in get_prep_value
        return int(value) ...
▶ Local vars
Request information

GET
No GET data
POST
No POST data
FILES
No FILES data
COOKIES
Variable    Value
csrftoken   
'KgE4Hjawc9E8fZ0IiozMXZsbzOCRkGNN'
tabstyle    
'html-tab'
META
Variable    Value
SYSTEMDRIVE 
'C:'
HTTP_ACCEPT_ENCODING    
'gzip, deflate, sdch'
FP_NO_HOST_CHECK    
'NO'
GATEWAY_INTERFACE   
'CGI/1.1'
SESSIONNAME 
'Console'
_OLD_VIRTUAL_PATH   
('C:\\Python34\\Lib\\site-packages\\PyQt4;C:\\ProgramData\\Oracle\\Java\\javapath;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program '
 'Files\\Java\\jdk1.8.0_51\\bin;C:\\Program '
 'Files\\Java\\jre1.8.0_51\\bin;C:\\Program Files '
 '(x86)\\Skype\\Phone\\;C:\\Program Files\\Microsoft\\Web Platform '
 'Installer\\;C:\\Python34\\;C:\\Program '
 'Files\\MongoDB\\Server\\3.0\\bin;C:\\Python34\\Scripts;C:\\Program Files '
 '(x86)\\MySQL\\MySQL Fabric 1.5.4 & MySQL Utilities 1.5.4 1.5\\;C:\\Program '
 'Files (x86)\\MySQL\\MySQL Fabric 1.5.4 & MySQL Utilities 1.5.4 '
 '1.5\\Doctrine extensions for PHP\\;C:\\Program Files\\nodejs;C:\\Program '
 'Files '
 '(x86)\\Brackets\\command;e:\\django\\PAS\\PASenv\\Scripts;C:\\Python34\\Lib\\site-packages\\PyQt4;C:\\ProgramData\\Oracle\\Java\\javapath;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program '
 'Files\\Java\\jdk1.8.0_51\\bin;C:\\Program '
 'Files\\Java\\jre1.8.0_51\\bin;C:\\Program Files '
 '(x86)\\Skype\\Phone\\;C:\\Program Files\\Microsoft\\Web Platform '
 'Installer\\;C:\\Python34\\;C:\\Program '
 'Files\\MongoDB\\Server\\3.0\\bin;C:\\Python34\\Scripts;C:\\Program Files '
 '(x86)\\MySQL\\MySQL Fabric 1.5.4 & MySQL Utilities 1.5.4 1.5\\;C:\\Program '
 'Files (x86)\\MySQL\\MySQL Fabric 1.5.4 & MySQL Utilities 1.5.4 '
 '1.5\\Doctrine extensions for '
 'PHP\\;C:\\Python34\\Lib\\site-packages\\PyQt4;C:\\ProgramData\\Oracle\\Java\\javapath;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program '
 'Files\\Java\\jdk1.8.0_51\\bin;C:\\Program '
 'Files\\Java\\jre1.8.0_51\\bin;C:\\Program Files '
 '(x86)\\Skype\\Phone\\;C:\\Program Files\\Microsoft\\Web Platform '
 'Installer\\;C:\\Python34\\;C:\\Program '
 'Files\\MongoDB\\Server\\3.0\\bin;C:\\Python34\\Scrip;C:\\Users\\Hp\\AppData\\Roaming\\npm')
NUMBER_OF_PROCESSORS    
'4'
PROGRAMW6432    
'C:\\Program Files'
HTTP_CACHE_CONTROL  
'max-age=0'
RUN_MAIN    
'true'
HTTP_ACCEPT 
'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
WINDIR  
'C:\\Windows'
HOMEDRIVE   
'C:'
wsgi.errors 
<_io.TextIOWrapper name='<stderr>' mode='w' encoding='cp437'>
COMMONPROGRAMFILES  
'C:\\Program Files (x86)\\Common Files'
HOMEPATH    
'\\Users\\Hp'
PROGRAMDATA 
'C:\\ProgramData'
REQUEST_METHOD  
'GET'
wsgi.file_wrapper   
''
QUERY_STRING    
''
PROCESSOR_LEVEL 
'6'
TEMP    
'C:\\Users\\Hp\\AppData\\Local\\Temp'
USERDOMAIN  
'SEKHAR-PC'
PROMPT  
'(env1) $P$G'
PUBLIC  
'C:\\Users\\Public'
USERNAME    
'Hp'
PSMODULEPATH    
'C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\Modules\\'
_OLD_VIRTUAL_PROMPT 
'$P$G'
COMPUTERNAME    
'SEKHAR-PC'
wsgi.multithread    
True
ALLUSERSPROFILE 
'C:\\ProgramData'
PROGRAMFILES    
'C:\\Program Files (x86)'
TMP 
'C:\\Users\\Hp\\AppData\\Local\\Temp'
wsgi.version    
(1, 0)
DJANGO_SETTINGS_MODULE  
'tutorial.settings'
COMMONPROGRAMFILES(X86) 
'C:\\Program Files (x86)\\Common Files'
CONTENT_TYPE    
'text/plain'
PATH    
('E:\\norestdjangorest\\env1\\Scripts;C:\\Python34\\Lib\\site-packages\\PyQt4;C:\\ProgramData\\Oracle\\Java\\javapath;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program '
 'Files\\Java\\jdk1.8.0_51\\bin;C:\\Program '
 'Files\\Java\\jre1.8.0_51\\bin;C:\\Program Files '
 '(x86)\\Skype\\Phone\\;C:\\Program Files\\Microsoft\\Web Platform '
 'Installer\\;C:\\Python34\\;C:\\Program '
 'Files\\MongoDB\\Server\\3.0\\bin;C:\\Python34\\Scripts;C:\\Program Files '
 '(x86)\\MySQL\\MySQL Fabric 1.5.4 & MySQL Utilities 1.5.4 1.5\\;C:\\Program '
 'Files (x86)\\MySQL\\MySQL Fabric 1.5.4 & MySQL Utilities 1.5.4 '
 '1.5\\Doctrine extensions for PHP\\;C:\\Program Files\\nodejs;C:\\Program '
 'Files '
 '(x86)\\Brackets\\command;e:\\django\\PAS\\PASenv\\Scripts;C:\\Python34\\Lib\\site-packages\\PyQt4;C:\\ProgramData\\Oracle\\Java\\javapath;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program '
 'Files\\Java\\jdk1.8.0_51\\bin;C:\\Program '
 'Files\\Java\\jre1.8.0_51\\bin;C:\\Program Files '
 '(x86)\\Skype\\Phone\\;C:\\Program Files\\Microsoft\\Web Platform '
 'Installer\\;C:\\Python34\\;C:\\Program '
 'Files\\MongoDB\\Server\\3.0\\bin;C:\\Python34\\Scripts;C:\\Program Files '
 '(x86)\\MySQL\\MySQL Fabric 1.5.4 & MySQL Utilities 1.5.4 1.5\\;C:\\Program '
 'Files (x86)\\MySQL\\MySQL Fabric 1.5.4 & MySQL Utilities 1.5.4 '
 '1.5\\Doctrine extensions for '
 'PHP\\;C:\\Python34\\Lib\\site-packages\\PyQt4;C:\\ProgramData\\Oracle\\Java\\javapath;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program '
 'Files\\Java\\jdk1.8.0_51\\bin;C:\\Program '
 'Files\\Java\\jre1.8.0_51\\bin;C:\\Program Files '
 '(x86)\\Skype\\Phone\\;C:\\Program Files\\Microsoft\\Web Platform '
 'Installer\\;C:\\Python34\\;C:\\Program '
 'Files\\MongoDB\\Server\\3.0\\bin;C:\\Python34\\Scrip;C:\\Users\\Hp\\AppData\\Roaming\\npm')
LOGONSERVER 
'\\\\SEKHAR-PC'
wsgi.multiprocess   
False
LOCALAPPDATA    
'C:\\Users\\Hp\\AppData\\Local'
OS  
'Windows_NT'
REMOTE_ADDR 
'127.0.0.1'
APPDATA 
'C:\\Users\\Hp\\AppData\\Roaming'
HTTP_COOKIE 
'tabstyle=html-tab; csrftoken=KgE4Hjawc9E8fZ0IiozMXZsbzOCRkGNN'
HTTP_HOST   
'127.0.0.1:8000'
CONTENT_LENGTH  
''
SERVER_PROTOCOL 
'HTTP/1.1'
PROCESSOR_REVISION  
'2a07'
VIRTUAL_ENV 
'E:\\norestdjangorest\\env1'
wsgi.input  
<_io.BufferedReader name=860>
PROGRAMFILES(X86)   
'C:\\Program Files (x86)'
PROCESSOR_ARCHITECTURE  
'x86'
wsgi.run_once   
False
USERPROFILE 
'C:\\Users\\Hp'
SERVER_PORT 
'8000'
PROCESSOR_IDENTIFIER    
'Intel64 Family 6 Model 42 Stepping 7, GenuineIntel'
VS100COMNTOOLS  
'C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Common7\\Tools\\'
COMSPEC 
'C:\\Windows\\system32\\cmd.exe'
PROCESSOR_ARCHITEW6432  
'AMD64'
SERVER_SOFTWARE 
'WSGIServer/0.2'
HTTP_CONNECTION 
'keep-alive'
CSRF_COOKIE 
'KgE4Hjawc9E8fZ0IiozMXZsbzOCRkGNN'
PATH_INFO   
'/snippets/'
SERVER_NAME 
'SEKHAR-PC'
HTTP_ACCEPT_LANGUAGE    
'en-US,en;q=0.8'
SCRIPT_NAME 
''
HTTP_USER_AGENT 
('Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) '
 'Chrome/48.0.2564.116 Safari/537.36')
REMOTE_HOST 
''
COMMONPROGRAMW6432  
'C:\\Program Files\\Common Files'
SYSTEMROOT  
'C:\\Windows'
wsgi.url_scheme 
'http'
HTTP_UPGRADE_INSECURE_REQUESTS  
'1'
PATHEXT 
'.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY'
Settings
Using settings module tutorial.settings
Setting Value
EMAIL_PORT  
25
SECURE_HSTS_INCLUDE_SUBDOMAINS  
False
TIME_ZONE   
'UTC'
SESSION_EXPIRE_AT_BROWSER_CLOSE 
False
SECURE_BROWSER_XSS_FILTER   
False
USE_TZ  
True
TEMPLATES   
[{'APP_DIRS': True,
  'BACKEND': 'django.template.backends.django.DjangoTemplates',
  'DIRS': [],
  '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']}}]
SECURE_SSL_REDIRECT 
False
ADMINS  
[]
LANGUAGES_BIDI  
['he', 'ar', 'fa', 'ur']
USE_X_FORWARDED_PORT    
False
DEBUG   
True
CSRF_HEADER_NAME    
'HTTP_X_CSRFTOKEN'
IGNORABLE_404_URLS  
[]
SECRET_KEY  
'********************'
PASSWORD_HASHERS    
'********************'
FILE_UPLOAD_TEMP_DIR    
None
CACHE_MIDDLEWARE_SECONDS    
600
FIRST_DAY_OF_WEEK   
0
DATE_FORMAT 
'N j, Y'
TIME_FORMAT 
'P'
SHORT_DATE_FORMAT   
'm/d/Y'
ALLOWED_HOSTS   
[]
DATABASE_ROUTERS    
[]
PASSWORD_RESET_TIMEOUT_DAYS 
'********************'
WSGI_APPLICATION    
'tutorial.wsgi.application'
DATETIME_FORMAT 
'N j, Y, P'
DEFAULT_INDEX_TABLESPACE    
''
INSTALLED_APPS  
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'rest_framework',
 'snippets']
MEDIA_ROOT  
''
LANGUAGE_CODE   
'en-us'
EMAIL_BACKEND   
'django.core.mail.backends.smtp.EmailBackend'
SESSION_COOKIE_PATH 
'/'
TEMPLATE_DIRS   
[]
SESSION_COOKIE_NAME 
'sessionid'
CSRF_COOKIE_DOMAIN  
None
EMAIL_SSL_KEYFILE   
'********************'
PREPEND_WWW 
False
STATIC_ROOT 
None
INTERNAL_IPS    
[]
USE_ETAGS   
False
TEST_RUNNER 
'django.test.runner.DiscoverRunner'
EMAIL_HOST_USER 
''
DATE_INPUT_FORMATS  
['%Y-%m-%d',
 '%m/%d/%Y',
 '%m/%d/%y',
 '%b %d %Y',
 '%b %d, %Y',
 '%d %b %Y',
 '%d %b, %Y',
 '%B %d %Y',
 '%B %d, %Y',
 '%d %B %Y',
 '%d %B, %Y']
SESSION_COOKIE_HTTPONLY 
True
THOUSAND_SEPARATOR  
','
LOGGING_CONFIG  
'logging.config.dictConfig'
SESSION_SAVE_EVERY_REQUEST  
False
CSRF_COOKIE_AGE 
31449600
CSRF_COOKIE_NAME    
'csrftoken'
DECIMAL_SEPARATOR   
'.'
MIDDLEWARE_CLASSES  
['django.middleware.security.SecurityMiddleware',
 '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']
CSRF_COOKIE_SECURE  
False
SHORT_DATETIME_FORMAT   
'm/d/Y P'
ROOT_URLCONF    
'tutorial.urls'
LANGUAGE_COOKIE_PATH    
'/'
LOGIN_URL   
'/accounts/login/'
FILE_UPLOAD_MAX_MEMORY_SIZE 
2621440
SETTINGS_MODULE 
'tutorial.settings'
LANGUAGE_COOKIE_DOMAIN  
None
LANGUAGES   
[('af', 'Afrikaans'),
 ('ar', 'Arabic'),
 ('ast', 'Asturian'),
 ('az', 'Azerbaijani'),
 ('bg', 'Bulgarian'),
 ('be', 'Belarusian'),
 ('bn', 'Bengali'),
 ('br', 'Breton'),
 ('bs', 'Bosnian'),
 ('ca', 'Catalan'),
 ('cs', 'Czech'),
 ('cy', 'Welsh'),
 ('da', 'Danish'),
 ('de', 'German'),
 ('el', 'Greek'),
 ('en', 'English'),
 ('en-au', 'Australian English'),
 ('en-gb', 'British English'),
 ('eo', 'Esperanto'),
 ('es', 'Spanish'),
 ('es-ar', 'Argentinian Spanish'),
 ('es-co', 'Colombian Spanish'),
 ('es-mx', 'Mexican Spanish'),
 ('es-ni', 'Nicaraguan Spanish'),
 ('es-ve', 'Venezuelan Spanish'),
 ('et', 'Estonian'),
 ('eu', 'Basque'),
 ('fa', 'Persian'),
 ('fi', 'Finnish'),
 ('fr', 'French'),
 ('fy', 'Frisian'),
 ('ga', 'Irish'),
 ('gd', 'Scottish Gaelic'),
 ('gl', 'Galician'),
 ('he', 'Hebrew'),
 ('hi', 'Hindi'),
 ('hr', 'Croatian'),
 ('hu', 'Hungarian'),
 ('ia', 'Interlingua'),
 ('id', 'Indonesian'),
 ('io', 'Ido'),
 ('is', 'Icelandic'),
 ('it', 'Italian'),
 ('ja', 'Japanese'),
 ('ka', 'Georgian'),
 ('kk', 'Kazakh'),
 ('km', 'Khmer'),
 ('kn', 'Kannada'),
 ('ko', 'Korean'),
 ('lb', 'Luxembourgish'),
 ('lt', 'Lithuanian'),
 ('lv', 'Latvian'),
 ('mk', 'Macedonian'),
 ('ml', 'Malayalam'),
 ('mn', 'Mongolian'),
 ('mr', 'Marathi'),
 ('my', 'Burmese'),
 ('nb', 'Norwegian Bokmal'),
 ('ne', 'Nepali'),
 ('nl', 'Dutch'),
 ('nn', 'Norwegian Nynorsk'),
 ('os', 'Ossetic'),
 ('pa', 'Punjabi'),
 ('pl', 'Polish'),
 ('pt', 'Portuguese'),
 ('pt-br', 'Brazilian Portuguese'),
 ('ro', 'Romanian'),
 ('ru', 'Russian'),
 ('sk', 'Slovak'),
 ('sl', 'Slovenian'),
 ('sq', 'Albanian'),
 ('sr', 'Serbian'),
 ('sr-latn', 'Serbian Latin'),
 ('sv', 'Swedish'),
 ('sw', 'Swahili'),
 ('ta', 'Tamil'),
 ('te', 'Telugu'),
 ('th', 'Thai'),
 ('tr', 'Turkish'),
 ('tt', 'Tatar'),
 ('udm', 'Udmurt'),
 ('uk', 'Ukrainian'),
 ('ur', 'Urdu'),
 ('vi', 'Vietnamese'),
 ('zh-hans', 'Simplified Chinese'),
 ('zh-hant', 'Traditional Chinese')]
LANGUAGE_COOKIE_NAME    
'django_language'
DATABASES   
{'default': {'ATOMIC_REQUESTS': False,
             'AUTOCOMMIT': True,
             'CONN_MAX_AGE': 0,
             'ENGINE': 'django.db.backends.sqlite3',
             'HOST': '',
             'NAME': 'e:\\norestdjangorest\\tutorial\\db.sqlite3',
             'OPTIONS': {},
             'PASSWORD': '********************',
             'PORT': '',
             'TEST': {'CHARSET': None,
                      'COLLATION': None,
                      'MIRROR': None,
                      'NAME': None},
             'TIME_ZONE': None,
             'USER': ''}}
LOGGING 
{}
DEFAULT_FROM_EMAIL  
'webmaster@localhost'
APPEND_SLASH    
True
TEMPLATE_DEBUG  
False
USE_L10N    
True
DEFAULT_TABLESPACE  
''
SESSION_SERIALIZER  
'django.contrib.sessions.serializers.JSONSerializer'
CSRF_FAILURE_VIEW   
'django.views.csrf.csrf_failure'
AUTH_USER_MODEL 
'auth.User'
SECURE_CONTENT_TYPE_NOSNIFF 
False
DEFAULT_CONTENT_TYPE    
'text/html'
AUTH_PASSWORD_VALIDATORS    
'********************'
LOGOUT_URL  
'/accounts/logout/'
EMAIL_USE_SSL   
False
CSRF_TRUSTED_ORIGINS    
[]
LANGUAGE_COOKIE_AGE 
None
EMAIL_TIMEOUT   
None
CACHE_MIDDLEWARE_KEY_PREFIX 
'********************'
CACHE_MIDDLEWARE_ALIAS  
'default'
USE_X_FORWARDED_HOST    
False
MESSAGE_STORAGE 
'django.contrib.messages.storage.fallback.FallbackStorage'
DEFAULT_CHARSET 
'utf-8'
SESSION_ENGINE  
'django.contrib.sessions.backends.db'
SESSION_COOKIE_AGE  
1209600
DEBUG_PROPAGATE_EXCEPTIONS  
False
DEFAULT_FILE_STORAGE    
'django.core.files.storage.FileSystemStorage'
SESSION_COOKIE_DOMAIN   
None
STATICFILES_DIRS    
[]
SESSION_CACHE_ALIAS 
'default'
FILE_UPLOAD_HANDLERS    
['django.core.files.uploadhandler.MemoryFileUploadHandler',
 'django.core.files.uploadhandler.TemporaryFileUploadHandler']
LOCALE_PATHS    

我尝试删除整个表并重新创建它,但它没有用。我提供了&#39;默认&#39;属性为所有者列,也不起作用。

1 个答案:

答案 0 :(得分:1)

您必须摆脱数据库和迁移文件夹。再次运行这些命令

rm -f tmp.db db.sqlite3  
rm -r snippets/migrations  
python manage.py makemigrations snippets  
python manage.py migrate