首页 > 代码库 > Django

Django

Last Update : 10/30/2016 16时48分

 

Django Project

Django documentation contents?

 

API Reference?

  • Applications
  • System check framework
  • Built-in class-based views API
  • Clickjacking Protection
  • contrib packages
  • Cross Site Request Forgery protection
  • Databases
  • django-admin and manage.py
  • Running management commands from your code
  • Django Exceptions
  • File handling
  • Forms
  • Middleware
  • Migration Operations
  • Models
  • Request and response objects
  • SchemaEditor
  • Settings
  • Signals
  • Templates
  • TemplateResponse and SimpleTemplateResponse
  • Unicode data
  • django.core.urlresolvers utility functions
  • django.conf.urls utility functions
  • Django Utils
  • Validators
  • Built-in Views

 

 

Built-in class-based views API?

Class-based views API reference. For introductory material, see the Class-based views topic guide.

  • Base views
    • View
    • TemplateView
    • RedirectView
  • Generic display views
    • DetailView
    • ListView
  • Generic editing views
    • FormView
    • CreateView
    • UpdateView
    • DeleteView
  • Generic date views
    • ArchiveIndexView
    • YearArchiveView
    • MonthArchiveView
    • WeekArchiveView
    • DayArchiveView
    • TodayArchiveView
    • DateDetailView
  • Class-based views mixins
    • Simple mixins
      • ContextMixin
      • TemplateResponseMixin
    • Single object mixins
      • SingleObjectMixin
      • SingleObjectTemplateResponseMixin
    • Multiple object mixins
      • MultipleObjectMixin
      • MultipleObjectTemplateResponseMixin
    • Editing mixins
      • FormMixin
      • ModelFormMixin
      • ProcessFormView
      • DeletionMixin
    • Date-based mixins
      • YearMixin
      • MonthMixin
      • DayMixin
      • WeekMixin
      • DateMixin
      • BaseDateListView
  • Class-based generic views - flattened index
    • Simple generic views
      • View
      • TemplateView
      • RedirectView
    • Detail Views
      • DetailView
    • List Views
      • ListView
    • Editing views
      • FormView
      • CreateView
      • UpdateView
      • DeleteView
    • Date-based views
      • ArchiveIndexView
      • YearArchiveView
      • MonthArchiveView
      • WeekArchiveView
      • DayArchiveView
      • TodayArchiveView
      • DateDetailView

 

Forms?

Detailed form API reference. For introductory material, see the Working with forms topic guide.

  • The Forms API
    • Bound and unbound forms
    • Using forms to validate data
    • Dynamic initial values
    • Checking which form data has changed
    • Accessing the fields from the form
    • Accessing "clean" data
    • Outputting forms as HTML
    • Binding uploaded files to a form
    • Subclassing forms
    • Prefixes for forms
  • Form fields
    • Core field arguments
    • Checking if the field data has changed
    • Built-in Field classes
    • Slightly complex built-in Field classes
    • Fields which handle relationships
    • Creating custom fields
  • Model Form Functions
  • Formset Functions
  • Widgets
    • Specifying widgets
    • Setting arguments for widgets
    • Widgets inheriting from the Select widget
    • Customizing widget instances
    • Base Widget classes
    • Built-in widgets
  • Form and field validation
    • Raising ValidationError
    • Using validation in practice

 

Working with forms?

  • Formsets
  • Creating forms from models
    • ModelForm
    • Model formsets
    • Inline formsets

 

Github

https://github.com/django/django/blob/master/django/forms/forms.py

 

 

Django

 

Startproject

Startapp

Configuration

url & view

template

http://www.douban.com/group/topic/42158933/

https://docs.djangoproject.com/en/1.4/topics/generic-views-migration/

https://github.com/disqus/django-mailviews/commit/31d6832128a591607796cfee32a30ce58919ca01#diff-1

 

Custom template tags and filters

https://docs.djangoproject.com/en/dev/howto/custom-template-tags/#howto-custom-template-tags

 

south & db

 

 

CRSF

https://docs.djangoproject.com/en/dev/ref/contrib/csrf/

 

static

https://docs.djangoproject.com/en/1.2/howto/static-files/

 

File Upload

https://docs.djangoproject.com/en/1.2/topics/http/file-uploads/

http://www.douban.com/group/topic/21131470/

 

plugin

ckeditor / kindeditor

http://blog.mondlab.com/python/django-ckeditor

http://2goo.info/blog/panjj/Django/2010/11/15/139

http://bbs.chinaunix.net/forum.php?mod=viewthread&tid=1836380

 

 

 

 

常见问题

ImproperlyConfigured: Middleware module "django.contrib.auth.middleware" does not define a "SessionAuthenticationMiddleware" class

 

运行python manage.py runserver时出现下面错误

Traceback (most recent call last):

  File "D:\Python27\lib\wsgiref\handlers.py", line 85, in run

    self.result = application(self.environ, self.start_response)

  File "D:\Python27\lib\site-packages\django\contrib\staticfiles\handlers.py", line 72, in __call__

    return self.application(environ, start_response)

  File "D:\Python27\lib\site-packages\django\core\handlers\wsgi.py", line 236, in __call__

    self.load_middleware()

  File "D:\Python27\lib\site-packages\django\core\handlers\base.py", line 57, in load_middleware

    raise exceptions.ImproperlyConfigured(‘Middleware module "%s" does not define a "%s" class‘ % (mw_module, mw_classname))

ImproperlyConfigured: Middleware module "django.contrib.auth.middleware" does not define a "SessionAuthenticationMiddleware" class

SessionAuthenticationMiddleware 这个是1.7里新加的,把 django版本升级就可以解决这个问题

 

如何查看 django版本?

import django

django.VERSION

 

还有一个方法是在 settings.py里删除SessionAuthenticationMiddleware

MIDDLEWARE_CLASSES = (

    ‘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‘,

)

 

SNIMissingWarning & InsecurePlatformWarning

D:\virtualenv\lwc-ws>pip install django==1.8

Collecting django==1.8

C:\Python27\lib\site-packages\pip-8.1.1-py2.7.egg\pip\_vendor\requests\packages

urllib3\util\ssl_.py:315: SNIMissingWarning: An HTTPS request has been made, but

the SNI (Subject Name Indication) extension to TLS is not available on this pla

tform. This may cause the server to present an incorrect TLS certificate, which

can cause validation failures. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#snimissingwarning.

  SNIMissingWarning
C:\Python27\lib\site-packages\pip-8.1.1-py2.7.egg\pip\_vendor\requests\packages

urllib3\util\ssl_.py:120: InsecurePlatformWarning: A true SSLContext object is n

ot available. This prevents urllib3 from configuring SSL appropriately and may c

ause certain SSL connections to fail. For more information, see https://urllib3.

readthedocs.org/en/latest/security.html#insecureplatformwarning.

  InsecurePlatformWarning

 

解决方法:

在cmd中输入:

pip install pyopenssl ndg-httpsclient pyasn1

 

上次生效版本:

pyOpenSSL==16.0.0

pyasn1==0.1.9

ndg-httpsclient==0.4.2

 

 

Could not find a version that satisfies the requirement djangocms-installer (from versions: )

No matching distribution found for djangocms-installer

 

使用-vvv打开debug信息

(django-cms) D:\virtualenv\django-cms>pip install djangocms-installer –vvv

 

Collecting djangocms-installer

  1 location(s) to search for versions of djangocms-installer:

  * https://pypi.python.org/simple/djangocms-installer/

  Getting page https://pypi.python.org/simple/djangocms-installer/

  Looking up "https://pypi.python.org/simple/djangocms-installer/" in the cache

  No cache entry available

  Starting new HTTPS connection (1): pypi.python.org

最后发现是fiddler开了的原因,关了就好了

 

django.core.exceptions.ImproperlyConfigured: LANGUAGE_CODE "zh-cn" must have a matching entry in LANGUAGES

https://docs.djangoproject.com/en/1.8/ref/settings/

 

Syncdb 1406 data too long for column ‘name‘

Verbose name can be too long

 

ImproperlyConfigured : There are duplicate field(s) in RailPackageAdmin.fieldsets

Fieldset sequence in admin should align with model definition

 

RegistrationForm‘ object has no attribute ‘clean_data

关于Django中出现上述问题的解决方法

code.djangoproject.com/wiki/BackwardsIncompatibleChanges#Newfo...Karen

上述网址第八条

Django语法更新

Newforms:clean_data------>cleaned_data

 

[u‘ManagementForm data is missing or has been tampered with‘]

Need prefix for formset

 

TemplateDoesNotExist

TEMPLATE_DIRS = (

‘simpleToDo/simpleToDo/templates‘

)

simpleToDo: folder

simpleToDo: package name

templates: html folder

 

Windows用户必须使用斜杠而不是反斜杠。 get_template() 假定的是 Unix 风格的文件名符号约定。

 

‘url‘ requires a non-empty first argument. . The syntax changed in Django 1.5, see the docs.

 

从django1.5 开始

{% url blog_content blog_id=id %}"

需要修改为:

{% url ‘blog_content‘ blog_id=id %}"

 

no such table auth user

‘NAME‘: ‘db.sqlite3‘

修改为

‘NAME‘: os.path.join(BASE_DIR,‘db.sqlite3‘)

 

No module named django.core

 

初步原因是装了多个版本的Python导致的。

解决方法之一就是直到dianjo安装目录所在的Python来执行这个命令。如:

python c:\python27\scripts\django-admin.py startproject mysite

以及

C:\Python27\python.exe manage.py runserver

这个问题就会解决了。

 

 

 

Django