1. 程式人生 > 實用技巧 >django和vue

django和vue

在寫樣式時實在不可以就用style


js的三元表示式
  條件 ? 真值 : 假值 
  1>2?'yes':'no'   => no
  2>1?'yes':'no'   => yes
python的三元表示式
  真值  if  條件  else  假值

在django檔案中使用呢redis需要的配置
# django-redis配置資訊
# reids資料庫預設是16個(redis.conf)  取值範圍 0-15
# 0 是我預設的資料庫
CACHES = {
    "default": {
        "BACKEND": "django_redis.cache.RedisCache
", "LOCATION": "redis://127.0.0.1:6379/2", "OPTIONS": { "CLIENT_CLASS": "django_redis.client.DefaultClient", "CONNECTION_POOL_KWARGS": {"max_connections": 100}, # "PASSWORD": "密碼", 'CONNECTION_POOL_KWARGS': {'decode_responses': True}, # 新增這一行,資料正常返回,否則將以bytes返回
} } } json 模組是用來轉換成str型別 json.dumps(goods) 這樣就把列表轉換成字串了 json.loads(name) 把字串型別轉成成原來的型別 在django中使用celery 1 新建一個python包(就是有init的) 2建立一個celery 把這些複製進去 from __future__ import absolute_import, unicode_literals import os from celery import Celery # set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'meiduo.settings') app = Celery('proj') # Using a string here means the worker doesn't have to serialize # the configuration object to child processes. # - namespace='CELERY' means all celery-related configuration keys # should have a `CELERY_` prefix. app.config_from_object('celery_tasks.config', namespace='CELERY') # Load task modules from all registered Django app configs. app.autodiscover_tasks() @app.task(bind=True) def debug_task(self): print('Request: {0!r}'.format(self.request)) 3 在manage.py 中複製os那一行把那個替換掉 4 把app的那一行setting這個去掉換成在此資料夾下的任務處理 服務端啟動命令 celery -A untitled1 worker --pool=solo -l info 客戶端啟動命令 python manage.py shell 在進入後需要把這個檔案下的celery匯入再去進行呼叫方法 需要呼叫的時候在這個方法後面加上.dalay() 抽象類 class Meta: abstract = True 抽象類 這是用來寫表的時候每個表都有共同的東西的時候所要寫的東西 onclick="sub()" 這是點選事件 var name == $("#name").val(); 宣告一個變數 $.post("/houtai/cate/". {'name': name}, function(){}) 用這樣來寫方法 地址 需要傳過去的變數 !在html中是非的意思 在需要繼承的中間寫 {% block content %} {% endblock %} 在需要寫的東西 在要寫的東西里面寫 {% extends 'common/public.html' %} {% block content %} 在這裡面寫需要寫的 {% endblock %} 在開發當中不能使用v-html 如果的post, put, delete 請求data 如果的get 請求 parms ,then(res=>{}, err=>{}) res是成功之後 err是失敗之後 在方法的括號裡面是一個物件(字典型別) 多對多 在表的裡面設定欄位 user = models.ManyToManyField(to='User') 這是多對多鍵的欄位型別 然後會在資料庫中出現一個新的表 is_valid() 這是用來判斷約束條件的 save() 返回的值是一個物件 如果是none就是新增失敗 是物件就是成功 write_only=True 這是在selalzer中只寫的約束 read_only=True 這是隻讀的約束 攔截器 router.beforeEach((to, from , next)=>{ if(to.path == '/login') return next() if(to.path !== '/login'){ let uid = sessionStorage.getItem('uid')