django學習遇到的問題解決方式


1、django.core.exceptions.ImproperlyConfigured: The TEMPLATE_DIRS setting must be a tuple. Please fix your settings.

解決方法:

在項目的setting.py文件中修改相關的文件腳本

TEMPLATE_DIRS = (
    os.path.join(os.path.dirname(__file__), 'templates').replace('\\', '/'),
)

 

2、“Unknown command syncdb” running “python manage.py syncdb”

由於使用了django1.9而1.9中的syncdb已被移除,因此如需創建數據庫則應該使用python.exe manage.py createsuperuser

進行重新初始化數據庫則需要使用一下方法

先manage.py makemigrations

再進行manage.py migrate

 

3、靜態的文件訪問問題

首先設置配置setting

STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
os.path.join( os.path.dirname(__file__),'static').replace('\\','/'),
)

其次設置配置templates路徑

TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
os.path.join( os.path.dirname(__file__),'tempates').replace('\\','/'),
)

最后可以進行訪問

<link rel="stylesheet" href="css/style.css" type="text/css">
<link rel="stylesheet" href="css/reset.css" type="text/css">
<link rel="stylesheet" href="css/home.css" type="text/css">
<script type="text/javascript" src="js/jquery-1.7.1.js"></script>
<script type="text/javascript" src="js/jquery.wookmark.js"></script>

訪問css等樣式

<link rel="stylesheet" href="../static/css/style.css" type="text/css">
<link rel="stylesheet" href="../static/reset.css" type="text/css">
<link rel="stylesheet" href="../static/css/home.css" type="text/css">
<script type="text/javascript" src="../static/js/jquery-1.7.1.js"></script>
<script type="text/javascript" src="../static/js/jquery.wookmark.js"></script>

4、WARNINGS:

?: (1_8.W001) The standalone TEMPLATE_* settings were deprecated in Django 1.8 a
nd the TEMPLATES dictionary takes precedence. You must put the values of the fol
lowing settings into your default TEMPLATES dict: TEMPLATE_DIRS.

解決方法:

把 TEMPLATE_DIRS 刪了

 

5、raise ImproperlyConfigured("settings.DATABASES is improperly configured. "

django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly co
nfigured. Please supply the ENGINE value. Check settings documentation for more
details.

解決方法:

 DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'blog',
        'USER': 'root',
        'PASSWORD': '123123',
        'HOST': '',
        'PORT': '',
    }
}
 
6、Python3.4使用pip安裝django報錯

E:\Python34\Scripts>pip
Fatal error in launcher: Unable to create process using '"E:\Python34\python.exe
" "E:\Python34\Scripts\pip.exe" '

 原因:由於路徑含有空格

解決辦法:python -m pip install Django

 
 
7、python3安裝MySQLdb報錯

原因:

1、由於其模塊已在Python3中不支持

2、缺失C++模塊

解決辦法:

重新安裝PyMySQL或者是安裝C++,並更改配置

VS120COMNTOOLS=D:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/Tools/

有而VS100COMNTOOLS沒有。

然后當然set VS100COMNTOOLS=%VS120COMNTOOLS%

另外,從D:/Program Files (x86)/Microsoft Visual Studio 12.0/VC下面拷貝一個vcvarsal.bat到

D:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/Tools/

下面即可。

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM