Python(Django 个人编)

seeting
 

STATICFILES_DIRS = (
    os.path.join(BASE_DIR,'static'),
)

 
models
 

from django.db import models
# Create your models here.
class Category(models.Model):
    caption = models.CharField(max_length=16)
class ActicleType(models.Model):
    caption = models.CharField(max_length=16)
class Article(models.Model):
    title = models.CharField(max_length=32)
    content = models.CharField(max_length=255)
    #category = models.ForeignKey(Category)
    #article_type = models.ForeignKey(ArticleType)
    # type_choice = (
    #     (0,'Python'),
    #     (1,'OpenStack'),
    #     (2,'Linux'),
    # )
    # article_type_id = models.IntegerField(choices=type_choice)

 
 
views
 

from django.shortcuts import render
from app01 import models
# Create your views here.
def article(request):
    result = models.Article.objects.all()
    return render(request,'article.html',{'result':result})

 
article.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <h1>查询结果</h1>
    {% for row in result %}
        <li>{{ row.id }}{{ row.title }}</li>
    {% endfor %}
</body>
</html>

说点什么

avatar
  Subscribe  
提醒