带有条件查询
filter
xclude
排序查询:
order_by()
分页
[:]
html django标签
如何使用标签
{%csrf_token%}
{%ul%}
{%for%}{%endfor%}
{%if%} {%else%} {%endif%}
---------------------------------------------------------------------------------modelForm
form-->Model
通过继承ModelFoem,编写其中的内部类
class Meta:
model=Student
fields
exclude
多选:MultipleChoiceField
文件上传:
form.FileField(upload_to="upload")手动处理
model.FileField(upload_to)这个用在自动保存上传文件
上传是ModelForm中必须传入request.FILES
urlCONF
视图
不使用django.contrib.staticfiles模块时,可以利用django.views.static.serve提供静态资源。用法简单,只要在urls.py使用下面的代码,一般除了开发时有静态资源,其他是不让写静态资源的:
urls.py
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
# ... the rest of your URLconf goes here ...
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
MEDIA_URL='/upload/')
settings.py
MEDIA_ROOT=os.path.join(BASE_DIR,"upload")
MEDIA_URL='/upload/'
shop页面管理
urls.py
MEDIA_ROOT=os.path.join(BASE_DIR,"upload")
MEDIA_URL='/upload/'
settings.py
STATICFILES_DIRS=(
os.path.join(BASE_DIR,"static")
)
连接mysql数据库
下载数据库:pip install mysqlclient
settings.py
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': "shopsys_db", 'HOST':"localhost", 'USER':"root", 'PASSWORD':"root", 'PORT':"3306" } }
INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'goods',//把名字导过来 ]
makemigrations 数据库名goods下的migrations下会有一个0001的文件
然后sqlmigrate数据库名称 0001把数据库迁移
页面加载创建一个static文件夹 把easyui导进来