django学习遇到的问题解决方式

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

解决方法:css

在项目的setting.py文件中修改相关的文件脚本html

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

 

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

因为使用了django1.9而1.9中的syncdb已被移除,所以如需建立数据库则应该使用python.exe manage.py createsuperusermysql

进行从新初始化数据库则须要使用一下方法jquery

先manage.py makemigrationssql

再进行manage.py migrate数据库

 

三、静态的文件访问问题django

首先设置配置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>

四、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 删了

 

五、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': '',
    }
}
 
六、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

 
 
七、python3安装MySQLdb报错

缘由:

一、因为其模块已在Python3中不支持

二、缺失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/

下面便可。

相关文章
相关标签/搜索