Build a personal blog
Preface:
Why do I blog?
Why did I start blogging? I'm not a big fan
This article tells me, not only me, but also the new rookie like me
To write a blog and build a website is not to show off knowledge, or to entertain, but to summarize their knowledge, improve the structure system, and express their feelings
Get to the point
1. Directory structure
The most important module is the article module of ArticleApp
Then there are user app modules about users, such as login, registration, comment Association, message, etc
Second, OtherApp and PersonalSpaceApp include personal news, announcements, broadcast messages, friend chains, etc
Other modules originally wanted to be more perfect, but for various reasons, let's see if we have time in the future. Originally, we wanted to build a hierarchical architecture, similar to mvc. Think of a small blog website, and then we gave up because of our lack of ability
2. Table structure
First map
Core module
Left to right, top to bottom
- User table
- Comment table: faher_comment_id is a self connection, which indicates whether it is a comment or a reply. If there is a comment, it indicates whether it is a reply
- Classification table
- Article table
- Tag article many to many middle table
- Tab table
- Thematic table
Edge module
- Friend list
- Personal dynamic table
- Announcement form
- User table
- guestbook
- Unfamiliar user table: automatically established according to ip, used to count the number of visitors and the number of visitors
3. Visit statistics
import uuid from django.db.models import F from UserApp.models import StrangeUser, UserAccount USER_KEY = 'uid' class UserAccessMiddleWare: def __init__(self,get_response): self.get_response = get_response def __call__(self,request): email = request.session.get('user_email') if email: //Increase access if the user is already logged in UserAccount.objects.filter(email=email).update(access_count = F('access_count')+1) request.user_account = UserAccount.objects.filter(email=email)[0] else: request.user_account = None sUser = self.get_sUser(request) request.sUser = sUser response = self.get_response(request) return response def get_sUser(self,request)://Obtain the ip address of unknown user and store it in the library uid = request.session.get(USER_KEY) if uid!=None: sUser = StrangeUser.objects.filter(uid=uid) sUser.update(access_count=F('access_count') + 1) return sUser[0] else: uid = request.META.get('REMOTE_ADDR') request.session.set_expiry(60*60*24*10) request.session[USER_KEY] = uid sUser = StrangeUser.objects.filter(uid=uid) if len(sUser): //Stock in if new user sUser.update(access_count=F('access_count')+1) else: sUser=[] ssUser = StrangeUser() ssUser.uid = uid ssUser.access_count = 1 ssUser.save() sUser.append(ssUser) return sUser[0]
4. Project screenshot
Demo address: http://www.binnb.top
github address: https://github.com/biningo/Biningo-Blog
Welcome star!