django开发流程以及数据库的测试问题
数据库的配置问题:
1配置:(使用mysql 的情况下)配置setting 时一定注意的是 DATABASE中的name 其中的NAME blog 对应的名字为blog 的数据库
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'blog'
# The following settings are not used with sqlite3:
'USER': 'root'
'PASSWORD': '',
'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '', # Set to empty string for default.
}
}
2.关于数据库的测试:
http://djangobook.py3k.cn/2.0/chapter05/,其中有详细的使用django操作数据库的内容
主要是
1)查找表中全部数据 a.objects.all()得到相应表内的数据 、
2)向表中插入数据是
p1 = Publisher(...) # At this point, p1 is not saved to the database yet! p1.save()
Django开发流程:
1.django-admin.py startproject project新建一个工程
2.在生成的目录中调用 python manage.py shell 如果出现了错误一定要注意是不是 在.bashrc中是否 添加了 DJANGO_SETTINGS_MODEULE,如果添加去掉 ,这里这个选项告诉shell去哪里读取相应的setting的内容。
3.python manage.py startapp appname 生成新的app ,在setting 中的 INSTALLED_APP中添加 ,一般如果新建工程为 demo,生成的app在demo 目录下 ,demo目录下还有一个demo,这里注意添加的时候只需要setting 中的 INSTALLED_APP添加上在appname就可以 。
4.添加 admin
5.url
html:
<h2> <a href="{%url blog_show post.id %}">{{post.title}}</a></h2>
urls.py:
url(r'^blog/(?P<id>\d+)/$',blog_show,name='blog_show')
这样就可以实现了点击题目完成到内容界面的切换了
这里的name对应的'blog_show'可以使任意的字符串但必须是唯一的,这个字符和url后面的 blog_show必须是一样的才能被调用
6。静态文件的处理。。。。。。。
主要是引用http://www.cnblogs.com/wenjiashe521/archive/2012/09/25/2701240.html
1) 在工程的目录下建立static的目录,在目录中加入bootstrap的内容
2)首先修改setting文件中的static files的部分:
import os
# Additional locations of static files
HERE = os.path.join( os.path.dirname(__file__), '../static/')
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/dja ngo/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
HERE,
)
3)然后在urls.py中加入static的url的映射:
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
urlpatterns += staticfiles_urlpatterns()
关键是这句话的问题
7下面需要学习的是bootstrap的相关知识了
posted on 2013-08-21 16:42 Practicer.. 阅读(174) 评论(0) 收藏 举报