django常用指令

virtualenv VENV 建立虚拟机环境
django-admin startproject myweb
python manage.py startapp mainsite
python manage.py runsever ip:port
python manage.py makemigrations模型生效
python manage.py migrate
python manage.py createsuperuser
pip freeze > requirement.txt
在settings.py中设置静态网页templates的存取地址
'DIRS' = [os.path.join(BASE_DIR,'templates')],
建立静态文件的存取地址

STATIC_URL = '/static/'
STATICFILES_DIRS = [
     os.path.join(BASE_DIR,'static')
]

使用mysql作为django的数据库:

     安装mysql,pip mysql-python

然后在settings.py中修改配置参数:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'mblog',
        'USER':'root',
        'PASSWORD':'258965',
        'HOST':'localhost',
        'PORT':'',
    }
}

最后再执行:

python manage.py makemigrations
python manage.py migrate

使用第三方服务发送电子邮件

http://mailgun.com

pip install django-mailgun
在settings.py中设置

EMAIL_BACKEND = 'django_mailgun.MailgunBackend'
MAILGUN_ACCESS_KEY = ''
MAILGUN_SERVERZ_NAME = ''

简单的验证机制

安装django-simple-captcha和Pillow

pip install django-simple-captcha
pip install Pillow

然后在settings.py中把'captcha' 加入到INSTALLED_APP中

python manage.py migrate

在urls.py中加入:

url(r'captcha/',include('captcha.urls')),

在需要验证的表单窗口ModelForm类中加上CaptchaField:

from captcha.fields import CaptchaField
class PostForm(forms.ModelForm):
    captcha - CaptchaField()

你可能感兴趣的:(django常用指令)