BBS (To be continued)

BBS pre-equipment

Database Configuration

1572612283741

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'bbs',
        'USER': 'root',
        'PASSWORD': 'root',
        'HOST' : '127.0.0.1',
        'PORT' : 3306,
        'CHARSET' : 'utf8',
        'OPTIONS': {
            'init_command': 'SET sql_mode="STRICT_TRANS_TABLES"',
            'charset': 'utf8mb4'
        }

    }
}

Table Creation

1572764055625

from django.db import models
from django.contrib.auth.models import AbstractBaseUser


# Create your models here.
class UserInfo(AbstractBaseUser):
    phone = models.BigIntegerField(null=True)
    avatar = models.FileField(upload_to='avatar/', default='avatar/default.jpg')
    create_time = models.DateField(auto_now_add=True)

    blog = models.OneToOneField(to='Blog', null=True)


class Blog(models.Model):
    site_name = models.CharField(max_length=32)
    site_title = models.CharField(max_length=64)
    site_theme = models.CharField(max_length=64)


class Category(models.Model):
    name = models.CharField(max_length=32)

    blog = models.ForeignKey(to='Blog', null=True)


class Tag(models.Model):
    name = models.CharField(max_length=32)

    blog = models.ForeignKey(to='Blog', null=True)


class Article(models.Model):
    title = models.CharField(max_length=64)
    desc = models.CharField(max_length=256)
    content = models.TextField()
    create_time = models.DateField(auto_now_add=True)

    # 数据库优化字段
    comment_num = models.BigIntegerField(default=0)
    up_num = models.BigIntegerField(default=0)
    down_num = models.BigIntegerField(default=0)

    # 外键字段
    blog = models.ForeignKey(to='Blog', null=True)
    tags = models.ManyToManyField(to='Tag', through='Article2Tag', through_fields=('article', 'tag'))
    category = models.ForeignKey(to='Category', null=True)


class Article2Tag(models.Model):
    article = models.ForeignKey(to='Article')
    tag = models.ForeignKey(to='Tag')


class UpandDown(models.Model):
    user = models.ForeignKey(to='UserInfo')
    article = models.ForeignKey(to='Article')
    is_up = models.BooleanField()


class Common(models.Model):
    user = models.ForeignKey(to='UserInfo')
    article = models.ForeignKey(to='Article')
    content = models.CharField(max_length=255)
    create_time = models.DateTimeField(auto_now_add=True)
    parent = models.ForeignKey(to='self', null=True)

Static configuration file

1572764301666

Forms forms

1572767536369

Add bootstrap style

1572865603273

widgets can re-point lead at the time does not come out from django.forms import widgets

Rendering the front page of the way

1572866046940

{% foo in form_obj %}
<p> {{foo.lable}}:{{foo}}</p>
{% endfor%}

Forms forms show an error message

1572866367425

foo.errors is a list of the information itself can not display color .o can get the first element of the list is a plain text colors have a

1572866701493

You can change the error message prompted by changing the forms of data in the form of error_messags

File Viewer

1572867256378

.change triggered when the contents of the box will change .onload projects completed before the implementation of the full implementation of

Since the first three is an asynchronous operation using all other fileReader onload completely executed before executing the

Registration function

Front-end data acquisition

1572876557602

Get File

1572870161306

$ () [0] Gets jQuery object into a JavaScript object, so that it can use JavaScript object properties and methods

.files [0] is the JavaScript file attributes is to get

.each()

1572869189606

Jquery cycle for loop

.serializeArray()

1572868925490

Internal labels will form all the common key to be packaged into a set of custom objects array line

1572869306801

ajax transfer files

1572869970737

ajax transfer files must modify these two parameters

Jump page

1572877202494

Jump page (remember to add the path /)

Adding class attributes

1572877377300

. addClass () method to add one or more elements to the selected class. This method does not remove the existing class attribute, only to add one or more class attributes. Tip: To add more classes, use class names separated by spaces.

has_error: This is a fixed wording, said in the input box error occurs, a red box will be reported, and when the cursor focus input box, will restore the original color

Analyzing logic backend

1572876639694

dictionary

1572878017812

ajax request to have a rear end of the callback function, there is usually provided a dictionary for spread front end

Url which can also add key, and then spread with a distal jsonresponse wrapped directly with the preceding

Guess you like

Origin www.cnblogs.com/bjlxxbj/p/11795449.html