add 完善用户登录状态和未登录状态
This commit is contained in:
@@ -3,15 +3,17 @@
|
||||
🌍
|
||||
*[English](/docs/README-en.md) ∙ [简体中文](README.md)*
|
||||
|
||||
版本:本项目基于`python3.11`和`Django4.2`进行开发的博客站点。
|
||||
版本:本项目基于`python3.10`和`Django4.2`进行开发的博客站点。
|
||||
|
||||
|
||||
## 主要功能:
|
||||
- 文章,页面,分类目录,标签的添加,删除,编辑等。文章、评论及页面支持`Markdown`,支持代码高亮。
|
||||
- 支持文章全文搜索。
|
||||
- 文章,页面,分类目录,标签的添加,删除,编辑等。
|
||||
- 文章、评论及页面支持`Markdown`,支持代码高亮。
|
||||
- 支持站内关键词搜索。
|
||||
- 完整的评论功能,包括发表回复评论,支持`Markdown`。
|
||||
- 侧边栏功能,最新文章,最多阅读,标签云等。
|
||||
## 待完成
|
||||
- 支持文章导入对应的脑图结构
|
||||
- 集成了简单的图床功能。
|
||||
- 集成`django-compressor`,自动压缩`css`,`js`。
|
||||
- 网站异常邮件提醒,若有未捕捉到的异常会自动发送提醒邮件。
|
||||
|
||||
Binary file not shown.
@@ -1,3 +1,83 @@
|
||||
from django.db import models
|
||||
|
||||
from django.conf import settings
|
||||
# Create your models here.
|
||||
|
||||
class AbstractModel(models.Model):
|
||||
"""
|
||||
一些通用的模型
|
||||
"""
|
||||
id = models.AutoField(primary_key=True)
|
||||
create_time = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)
|
||||
update_time = models.DateTimeField(verbose_name='修改时间', auto_now=True)
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
|
||||
class Tag(AbstractModel):
|
||||
"""
|
||||
Blog标签
|
||||
"""
|
||||
blog_tag = models.CharField(verbose_name='Blog标签', max_length=64) # Blog标签名称
|
||||
|
||||
class Meta:
|
||||
db_table = 'Blog_Tag'
|
||||
ordering = ['blog_tag']
|
||||
verbose_name = "Blog标签"
|
||||
verbose_name_plural = verbose_name
|
||||
|
||||
def __str__(self):
|
||||
return self.blog_tag
|
||||
|
||||
|
||||
class Category(AbstractModel):
|
||||
name = models.CharField(verbose_name='Blog分类', max_length=64) # Blog分类
|
||||
|
||||
class Meta:
|
||||
db_table = 'Blog_Category'
|
||||
ordering = ['name']
|
||||
verbose_name = "Blog分类"
|
||||
verbose_name_plural = verbose_name
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class XiaoBlog(AbstractModel):
|
||||
"""
|
||||
Blog本体model
|
||||
"""
|
||||
author = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name='作者', on_delete=models.CASCADE)
|
||||
|
||||
title = models.CharField(verbose_name='Blog标题',max_length=128) # Blog标题
|
||||
auto_time = models.DateField(verbose_name='自定义Blog展示日期',auto_now_add=True) # Blog日期
|
||||
content = models.TextField(verbose_name='正文',blank=True, null=True)
|
||||
digest = models.TextField(verbose_name='摘要',blank=True, null=True)
|
||||
view = models.BigIntegerField(default=0) # 阅读数
|
||||
comment = models.BigIntegerField(default=0) # 评论数
|
||||
# picture = models.CharField(max_length=200) # 图片地址
|
||||
|
||||
blog_category = models.ForeignKey(to='Category', verbose_name='Blog类别', on_delete=models.CASCADE) # Blog标签
|
||||
blog_tag = models.ManyToManyField(Tag) # Blog标签
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
||||
def viewed(self):
|
||||
"""
|
||||
阅读数++
|
||||
"""
|
||||
self.view += 1
|
||||
self.save(update_fields=['view'])
|
||||
def commenced(self):
|
||||
"""
|
||||
评论数++
|
||||
"""
|
||||
self.comment += 1
|
||||
self.save(update_fields=['comment'])
|
||||
class Meta:
|
||||
# 按时间降序
|
||||
db_table = 'Blog_Content'
|
||||
ordering = ['-auto_time']
|
||||
verbose_name = "Blog正文"
|
||||
verbose_name_plural = verbose_name
|
||||
|
||||
Binary file not shown.
@@ -9,6 +9,10 @@ def to_index(request):
|
||||
site_title_first = "在星河中"
|
||||
site_title = "在星河中"
|
||||
site_one = "心之何如,有似万丈迷津,遥亘千里,其中并无舟子可渡人,除了自渡,他人爱莫能助。"
|
||||
user = request.user
|
||||
print("---------------------------")
|
||||
print(user)
|
||||
|
||||
data = {"site_title_first":site_title_first,"site_title":site_title,"site_one":site_one}
|
||||
|
||||
return render(request, "html/index.html",data)
|
||||
|
||||
Binary file not shown.
@@ -6,5 +6,5 @@ urlpatterns = [
|
||||
# re_path(r'^login/$', views.login),
|
||||
path('register', RegisterView.as_view()), # 用户注册
|
||||
path('login', LoginView.as_view()), # 用户登录
|
||||
path('logout', LogoutView.as_view()), # 用户登出
|
||||
path('logout', LogoutView.as_view(),name="logout_fun"), # 用户登出
|
||||
]
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class SiteSiteConfig(AppConfig):
|
||||
default_auto_field = "django.db.models.BigAutoField"
|
||||
name = "site_site"
|
||||
Binary file not shown.
@@ -0,0 +1,3 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
@@ -0,0 +1,8 @@
|
||||
from django.urls import path, include,re_path
|
||||
from . import views
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
# re_path(r'^index/$',views.IndexView.as_view()),
|
||||
# re_path(r'^login/$', views.login),
|
||||
]
|
||||
@@ -0,0 +1,3 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
||||
@@ -75,13 +75,24 @@ NAVBAR
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="./about.html"><span class="badge badge-dark">友链</span></a>
|
||||
</li>
|
||||
{% if user.is_authenticated %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="./about.html"><span class="badge badge-primary">后台管理</span></a>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
{% if user.is_authenticated %}
|
||||
<a><span class="badge">{{user.username}}</span></a>
|
||||
{% else %}
|
||||
<a><span class="badge">用户未登录,游客模式</span></a>
|
||||
{% endif %}
|
||||
<ul class="navbar-nav ml-auto d-flex align-items-center">
|
||||
<li class="nav-item highlight">
|
||||
<a class="nav-link" href="{% url 'login_jump' %}?#">Login</a>
|
||||
{% if user.is_authenticated %}
|
||||
<a class="nav-link" href="{% url 'logout_fun' %}?#">Logout</a>
|
||||
{% else %}
|
||||
<a class="nav-link" href="{% url 'login_jump' %}?#">Login</a>
|
||||
{% endif %}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -44,6 +44,7 @@ INSTALLED_APPS = [
|
||||
"server_auth",
|
||||
"blog",
|
||||
"jump",
|
||||
"site_site",
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
|
||||
@@ -26,4 +26,6 @@ urlpatterns = [
|
||||
re_path("^api/account/",include('server_auth.urls')),
|
||||
# blog管理
|
||||
re_path("^api/blog/",include('blog.urls')),
|
||||
# 站点管理
|
||||
re_path("^api/site/",include('site_site.urls')),
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user