Notes for Studying Django】的更多相关文章

Once you added a new application to INSTALLED_APPS, the database tables need to be updated, thus you need to run python manage.py syncdb. Normally the server auto-reloads code every time you modify a file, but creating a new file does not trigger the…
The first time I came across django was last month.. Since then I was considering it as the better choice of building/maintaining websites. Now I think it is its auto-gen sql and commitments of changes makes it convienient of making changes. Only 3 s…
form 也没什么可说的,我只给一个例子大家就懂了 form model from django import forms class UserForm(forms.Form): username = forms.CharField(label='UserName', max_length=100) password = forms.CharField(label='Password', max_length=20, widget=forms.PasswordInput()) views.py…
CRUD 也没什么可说的,django 提供了完善的 orm  api, 直接用就行了. 我只贴几个列子,一看就明白了,自己再用用就熟了. # create b = Blog(name='Beatles Blog', tagline='All the latest Beatles news.') b.save() # create and save Blog.objects.create(name='Beatles Blog', tagline='All the latest Beatles n…
models 其实也没什么好说的,就是普通的 python 类 settings 中配置数据库连接 DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'mydb', 'USER': 'root', 'PASSWORD': '', 'HOST': '127.0.0.1', ', } } 定义自己的 models class User(models.Model): class Meta: verbose_…
views 其实没什么可看的, 在  django  中 views 就是 controller, 是处理请求的, 就是一个普通的 python 方法. 一般从 request 中提取请求参数, 然后处理业务逻辑, 跟数据库和后台服务做交互,取回数据,渲染模板,将返回结果包装进  HttpResponse 然后返回. def view_index(request): return HttpResponse(content='hello world') def view_index(request…
django 中有 2种 Template Loader django.template.loaders.filesystem.Loader django.template.loaders.app_directories.Loader filesystem.Loader 会根据 settings 中  TEMPLATES 下配置的 DIRS  查找 template TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.Djang…
一般在 settings.py 中会有一个  ROOT_URLCONF ,请求到来时 django 会从 ROOT_URLCONF 指向的文件中查找  urlpatterns 变量配置的路由. urlpatterns 中还可以 include 其它 model 中的 urlpatterns, django 会从上到下一个一个查找,看 url 是否匹配. 匹配后就交给对应的 view 处理了. urlpatterns = [ url(r'^admin/', include(admin.site.u…
公司 web 框架用的是 django, 以前没用过,打算这两周好好看看. 边学习边整理一下笔记,加深理解. 好像谁说过初学者更适合写入门级的教程,我觉得有一定道理. 高手写的教程有一定深度,不会写入门级的教程,像 深入理解Java虚拟机:JVM高级特性与最佳实践 之类. 大家写的都是经典,像 SICP  The c programming language 等等. 基础的东西都很好学,是必备能力.在掌握基础的同时还应该多修炼修炼内功.内外兼修,努力使自己成为更优秀的工程师.…
EXTRACTED from the Django document It's a common need to filter down the objects given in a list page by some key in the URL. Handily, the ListView has a get_queryset() method we can override. Previously, it has just been returning the value of the q…