[笔记]Writing your first Django app

https://docs.djangoproject.com/en/1.9/intro/


###SETUP:

$ django-admin startproject mysite
$ python manage.py runserver   /    $ python manage.py runserver 0.0.0.0:8000
$ python manage.py startapp polls


views.py:
def index(request):
    return HttpResponse("Hello, world. You're at the polls index.")


urls.py:
urlpatterns = [
    url(r'^polls/', include('polls.urls')),
    url(r'^admin/', admin.site.urls),
]


###DB: mysite/settings.py
DATABASES =    ENGINE , NAME




###MODELS: models.py
class Question(models.Model):
    question_text = models.CharField(max_length=200)
    pub_date = models.DateTimeField('date published')
class Choice(models.Model):
    question = models.ForeignKey(Question, on_delete=models.CASCADE)
    choice_text = models.CharField(max_length=200)
    votes = models.IntegerField(default=0)


###MIGRATIONS:mysite/settings.py
INSTALLED_APPS = [
    'polls.apps.PollsConfig', ….


$ python manage.py makemigrations polls
$ python manage.py sqlmigrate polls 0001
$ python manage.py migrate




###ADMIN:
$ python manage.py createsuperuser



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值