Django Python MySql 問題集錦

來源:互聯網
上載者:User

標籤:mysql   linux   web   django   

問題 1:

raise ImproperlyConfigured("settings.DATABASES is improperly configured. " django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details. 

解決思路:

請先確認DATABASES節點中配置正常,

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/59/6C/wKiom1TSQMvSQKTUAADGnYwV4GE730.jpg" title="2015-02-04 23_22_32.png" alt="wKiom1TSQMvSQKTUAADGnYwV4GE730.jpg" />


請檢查是否有多少 settings.py檔案.如果是請逐個檢查對應節點.


問題 2:

ImportError: No module named XXX

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/59/69/wKioL1TSQaCQiJZKAABqn_7sVDs355.jpg" title="2015-02-04 23_48_3.png" alt="wKioL1TSQaCQiJZKAABqn_7sVDs355.jpg" />

解決思路:

請確認這裡到底該不該用include


問題3:

Warning:

Incorrect string value: ‘\xE5\xBC\xA0\xE4\xB8\x89‘ for column ‘username‘ at row 1

解決:

很明顯,是因為字元亂碼的問題.造成的。

所以需要mysql支援中文,那麼就去更改mysql的字元集.

方式一: 在建立時就指定預設如:

mysql>  create database test default charset=utf8;

然後再同步產生sql:

>>> python manage.py syncdb


方式二:

mysql > ALTER DATABASE bugzero_db CHARACTER SET utf-8;

這種方式只有在資料庫中沒有table的情況下才work


方式三:


  1. mysql> SET character_set_client = utf8 ;  

  2. mysql> SET character_set_connection = utf8 ;   

  3. mysql> SET character_set_database = utf8 ;   

  4. mysql> SET character_set_results = utf8 ;    

  5. mysql> SET character_set_server = utf8 ;   


  6. mysql> SET collation_connection = utf8 ;  

  7. mysql> SET collation_database = utf8 ;   

  8. mysql> SET collation_server = utf8 ;

但是這種方法在發送查詢或進行與mysql互動時最好還是要加:

SET NAMES ‘utf8‘;

相當於:

  1. SET character_set_client = utf8;  

  2. SET character_set_results = utf8;   

  3. SET character_set_connection = utf8;

不然還是不正常工作.





Forbidden (403)

CSRF verification failed. Request aborted.
Help

Reason given for failure:

    CSRF token missing or incorrect.
    

In general, this can occur when there is a genuine Cross Site Request Forgery, or when Django‘s CSRF mechanism has not been used correctly. For POST forms, you need to ensure:

    Your browser is accepting cookies.
    The view function uses RequestContext for the template, instead of Context.
    In the template, there is a {% csrf_token %} template tag inside each POST form that targets an internal URL.
    If you are not using CsrfViewMiddleware, then you must use csrf_protect on any views that use the csrf_token template tag, as well as those that accept the POST data.

You‘re seeing the help section of this page because you have DEBUG = True in your Django settings file. Change that to False, and only the initial error message will be displayed.

You can customize this page using the CSRF_FAILURE_VIEW setting.

解決方案:開發過程中可暫時注釋settings.py中的

‘django.middleware.csrf.CsrfViewMiddleware‘,



由於剛剛接觸python , django, mysql也是頭一次接觸所以可能遇到的都是小白問題,為了自己備忘,說不定也可以協助到各位.


連載 ing..歡迎各位補充.

本文出自 “狼之魂” 部落格,請務必保留此出處http://itwolf.blog.51cto.com/3286625/1611699

Django Python MySql 問題集錦

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.