first commit

main
blog 6 months ago
parent 2ece1124fe
commit f426199d3d

@ -0,0 +1,8 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="FacetManager">
<facet type="django" name="Django">
<configuration>
<option name="rootFolder" value="$MODULE_DIR$" />
<option name="settingsModule" value="blog/settings.py" />
<option name="manageScript" value="$MODULE_DIR$/manage.py" />
<option name="environment" value="&lt;map/&gt;" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TemplatesService">
<option name="TEMPLATE_CONFIGURATION" value="Django" />
<option name="TEMPLATE_FOLDERS">
<list>
<option value="$MODULE_DIR$/../blog\templates" />
</list>
</option>
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
</component>
</module>

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.12" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12" project-jdk-type="Python SDK" />
</project>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/blog.iml" filepath="$PROJECT_DIR$/.idea/blog.iml" />
</modules>
</component>
</project>

Binary file not shown.

@ -0,0 +1,134 @@
"""
Django settings for blog project.
Generated by 'django-admin startproject' using Django 1.11.6.
For more information on this file, see
https://docs.djangoproject.com/en/1.11/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.11/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
from django.conf import global_settings
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'ry!upfimxiq7+559yq3skd%xc6+7dml(+lmy_n#ylw8!#ub-ld'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'post'
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'blog.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')]
,
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'blog.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': '180810db',
'USER': 'root',
'PASSWORD': '123456',
'HOST': '127.0.0.1',
'PORT': '3306'
}
}
# Password validation
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/
LANGUAGE_CODE = 'zh-Hans'
TIME_ZONE = 'Asia/Shanghai'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR,'static','css')
]
# global_settings

Binary file not shown.

@ -0,0 +1,22 @@
"""blog URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.11/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url, include
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^', include('post.urls')),
]

Binary file not shown.

@ -0,0 +1,16 @@
"""
WSGI config for blog project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "blog.settings")
application = get_wsgi_application()

Binary file not shown.

Binary file not shown.

@ -0,0 +1,22 @@
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "blog.settings")
try:
from django.core.management import execute_from_command_line
except ImportError:
# The above import may fail for some other reason. Ensure that the
# issue is really that Django is missing to avoid masking other
# exceptions on Python 2.
try:
import django
except ImportError:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
)
raise
execute_from_command_line(sys.argv)

@ -0,0 +1,17 @@
# coding:utf-8
from django.apps import AppConfig
import os
default_app_config = 'post.PrimaryBlogConfig'
VERBOSE_APP_NAME = u"博客管理"
def get_current_app_name(_file):
return os.path.split(os.path.dirname(_file))[-1]
class PrimaryBlogConfig(AppConfig):
name = get_current_app_name(__file__)
verbose_name = VERBOSE_APP_NAME

Binary file not shown.

@ -0,0 +1,13 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.contrib import admin
from .models import *
# Register your models here.
class PostModelAdmin(admin.ModelAdmin):
list_display = ('title','created')
admin.site.register(Category)
admin.site.register(Tag)
admin.site.register(Post,PostModelAdmin)

Binary file not shown.

@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.apps import AppConfig
class PostConfig(AppConfig):
name = 'post'

@ -0,0 +1,56 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2018-08-10 07:51
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Category',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('cname', models.CharField(max_length=30, unique=True)),
],
options={
'db_table': 't_category',
},
),
migrations.CreateModel(
name='Post',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=100, unique=True)),
('desc', models.CharField(max_length=100)),
('content', models.TextField()),
('created', models.DateTimeField(auto_now_add=True)),
('category', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='post.Category')),
],
options={
'db_table': 't_post',
},
),
migrations.CreateModel(
name='Tag',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('tname', models.CharField(max_length=30, unique=True)),
],
options={
'db_table': 't_tag',
},
),
migrations.AddField(
model_name='post',
name='tag',
field=models.ManyToManyField(to='post.Tag'),
),
]

@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
# Create your models here.
class Category(models.Model):
cname = models.CharField(max_length=30,unique=True,verbose_name=u'类别名称')
class Meta:
db_table = 't_category'
verbose_name_plural=u'类别'
def __unicode__(self):
return u'Category:%s'%self.cname
class Tag(models.Model):
tname = models.CharField(max_length=30,unique=True,verbose_name=u'标签名称')
class Meta:
db_table = 't_tag'
verbose_name_plural = u'标签'
def __unicode__(self):
return u'Tag:%s' % self.tname
class Post(models.Model):
title = models.CharField(max_length=100,unique=True)
desc = models.CharField(max_length=100)
content = models.TextField()
created = models.DateTimeField(auto_now_add=True)
category = models.ForeignKey(Category,on_delete=models.CASCADE)
tag = models.ManyToManyField(Tag)
class Meta:
db_table = 't_post'
verbose_name_plural = u'帖子'
def __unicode__(self):
return u'Post:%s' % self.title

Binary file not shown.

@ -0,0 +1,39 @@
{% extends 'base.html' %}
{% load myfilter %}
{% block title %}
详情页面
{% endblock %}
{% block left %}
<div id="main">
<article class="article article-type-post">
<div class="article-meta">
<a class="article-date">
<time>{{ post.created|date:'Y-m-d H:i:s' }}</time>
</a>
<div class="article-category">
<a class="article-category-link" href="#" target="_blank">{{ post.category.cname }}</a>
</div>
</div>
<div class="article-inner">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title">{{ post.title }}</a>
</h1>
</header>
<div class="article-entry" itemprop="articleBody">
<h2>前言</h2>
{{ post.desc }}
<hr>
{{ post.content|md|safe }}
</div>
</div>
</article>
<div class="bdsharebuttonbox"><a href="#" class="bds_more" data-cmd="more"></a><a href="#" class="bds_qzone" data-cmd="qzone"></a><a href="#" class="bds_tsina" data-cmd="tsina"></a><a href="#" class="bds_tqq" data-cmd="tqq"></a><a href="#" class="bds_renren" data-cmd="renren"></a><a href="#" class="bds_weixin" data-cmd="weixin"></a></div>
<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdPic":"","bdStyle":"0","bdSize":"16"},"share":{},"image":{"viewList":["qzone","tsina","tqq","renren","weixin"],"viewText":"分享到:","viewSize":"16"},"selectShare":{"bdContainerClass":null,"bdSelectMiniList":["qzone","tsina","tqq","renren","weixin"]}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
</div>
{% endblock %}

@ -0,0 +1,111 @@
{% extends 'base.html' %}
{% block title %}首页{% endblock %}
{% block left %}
<div id="main">
{% for post in postList %}
<article class="article article-type-post">
<div class="article-meta">
<a class="article-date">
<time>{{ post.created|date:'Y-m-d H:i:s' }}</time>
</a>
<div class="article-category">
<a class="article-category-link" href="#" target="_blank">{{ post.category.cname }}</a>
</div>
</div>
<div class="article-inner">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="#" target="_blank">{{ post.title }}</a>
</h1>
</header>
<div class="article-entry" itemprop="articleBody">
<h2>前言</h2>
<hr>
{{ post.desc }}
<p class="article-more-link">
<a href="/post/{{ post.id }}" target="_blank">阅读全文</a>
</p>
</div>
<footer class="article-footer">
<a data-url="存放文章的url" class="article-share-link">分享</a>
<ul class="article-tag-list">
{% for t in post.tag.all %}
<li class="article-tag-list-item">
<a class="article-tag-list-link" href="#">{{ t.tname }}</a>
</li>
{% endfor %}
</ul>
</footer>
</div>
</article>
{% endfor %}
<nav id="page-nav">
{% if postList.has_previous %}
<a class="extend prev" rel="next" href="/page/{{ postList.previous_page_number }}">« Prev</a>
{% endif %}
{% for page in pageList %}
{% if currentNum == page %}
<span class="page-number current">{{ page }}</span>
{% else %}
<a class="page-number" href="/page/{{ page }}">{{ page }}</a>
{% endif %}
{% endfor %}
{% if postList.has_next %}
<a class="extend next" rel="next" href="/page/{{ postList.next_page_number }}">Next »</a>
{% endif %}
</nav>
</div>
{% endblock %}

@ -0,0 +1,10 @@
#coding=utf-8
from django.template import Library
register = Library()
@register.filter
def md(value):
import markdown
return markdown.markdown(value)

@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.test import TestCase
# Create your tests here.

@ -0,0 +1,10 @@
#coding=utf-8
from django.conf.urls import url
import views
urlpatterns=[
url(r'^$',views.queryAll),
url(r'^page/(\d+)$',views.queryAll),
url(r'^post/(\d+)$',views.detail),
]

Binary file not shown.

@ -0,0 +1,56 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.shortcuts import render
# Create your views here.
#渲染主页面
# from post.models import Post
from templates.models import Post
from django.core.paginator import Paginator
import math
def queryAll(request,num=1):
num = int(num)
#获取所有帖子信息
postList = Post.objects.all().order_by('-created')
#创建分页器对象
pageObj = Paginator(postList,1)
#获取当前页的数据
perPageList = pageObj.page(num)
#生成页码数列表
# 每页开始页码
begin = (num - int(math.ceil(10.0 / 2)))
if begin < 1:
begin = 1
# 每页结束页码
end = begin + 9
if end > pageObj.num_pages:
end = pageObj.num_pages
if end <= 10:
begin = 1
else:
begin = end - 9
pageList = range(begin, end + 1)
return render(request,'index.html',{'postList':perPageList,'pageList':pageList,'currentNum':num})
#阅读全文功能
def detail(request,postid):
postid = int(postid)
#根据postid查询帖子的详情信息
post = Post.objects.get(id=postid)
return render(request,'detail.html',{'post':post})

Binary file not shown.

File diff suppressed because it is too large Load Diff

@ -0,0 +1,57 @@
<!DOCTYPE html>
<!-- saved from url=(0035)http://hello123.pythonanywhere.com/ -->
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>{% block title %}{% endblock %}</title>
<link rel="stylesheet" type="text/css" href="/static/style.css">
<style>
form {
position: relative;
width: 150px;
margin: 0 auto;
}
.d1{
float: right;
line-height: 67px;
}
.d1 input {
width: 100px;
height: 30px;
border: 2px solid darkred;
border-radius: 5px;
outline: none;
background: white;
color: #1e242a;
}
</style>
{% block headerjs %}
{% endblock %}
</head>
<body>
<div id="container">
<div id="wrap">
{% include 'header.html' %}
<div class="outer">
{% block left %}
{% endblock %}
{% include 'right.html' %}
</div>
{% include 'footer.html' %}
</div>
</div>
</body>
</html>

@ -0,0 +1,9 @@
<footer id="footer">
<div class="outer">
<div id="footer-info" class="inner">
© 叶子<br>
Powered by <a href="http://hello123.pythonanywhere.com/#" target="_blank">Hexo</a>
Theme by <a href="http://hello123.pythonanywhere.com/#" target="_blank">BJSXT_B207班</a>
</div>
</div>
</footer>

@ -0,0 +1,17 @@
<header id="header">
<div id="banner"></div>
<div id="header-outer" class="outer">
<div id="header-inner" class="inner">
<nav id="main-nav">
<a class="main-nav-link" href="http://hello123.pythonanywhere.com/">首页</a>
<a class="main-nav-link" href="http://hello123.pythonanywhere.com/archive/">归档</a>
<a class="main-nav-link" href="http://hello123.pythonanywhere.com/aboutme" target="_blank">关于</a>
</nav>
<div class="d1">
<form method="get" action="http://hello123.pythonanywhere.com/search/">
<input type="text" name="q" placeholder="搜索">
</form>
</div>
</div>
</div>
</header>

@ -0,0 +1,109 @@
<aside id="sidebar">
<!--分类-->
<div class="widget-wrap">
<h3 class="widget-title">分类</h3>
<div class="widget">
<ul class="category-list">
<li class="category-list-item">
<a class="category-list-link" href="http://hello123.pythonanywhere.com/category/1">前端</a>
<span class="category-list-count">4</span>
</li>
<li class="category-list-item">
<a class="category-list-link" href="http://hello123.pythonanywhere.com/category/2">后端</a>
<span class="category-list-count">3</span>
</li>
<li class="category-list-item">
<a class="category-list-link" href="http://hello123.pythonanywhere.com/category/3">数据库</a>
<span class="category-list-count">1</span>
</li>
</ul>
</div>
</div>
<!--归档-->
<div class="widget-wrap">
<h3 class="widget-title">归档</h3>
<div class="widget">
<ul class="archive-list">
<li class="archive-list-item">
<a class="archive-list-link" href="http://hello123.pythonanywhere.com/archive/2018/06">2018年06月</a>
<span class="archive-list-count">6</span>
</li>
<li class="archive-list-item">
<a class="archive-list-link" href="http://hello123.pythonanywhere.com/archive/2017/05">2017年05月</a>
<span class="archive-list-count">1</span>
</li>
<li class="archive-list-item">
<a class="archive-list-link" href="http://hello123.pythonanywhere.com/archive/2017/06">2017年06月</a>
<span class="archive-list-count">1</span>
</li>
</ul>
</div>
</div>
<!--近期文章-->
<div class="widget-wrap">
<h3 class="widget-title">近期文章</h3>
<div class="widget">
<ul>
<li>
<a href="http://hello123.pythonanywhere.com/post/8" target="_blank">T4</a>
</li>
<li>
<a href="http://hello123.pythonanywhere.com/post/7" target="_blank">T3</a>
</li>
<li>
<a href="http://hello123.pythonanywhere.com/post/4" target="_blank">MySQL表连接</a>
</li>
</ul>
</div>
</div>
<div class="widget-wrap">
<h3 class="widget-title">友情链接</h3>
<div class="widget">
<ul>
<li>
<a href="http://www.bjsxt.com/" target="_blank">尚学堂</a>
</li>
<li>
<a href="http://www.sxt.cn/" target="_blank">速学堂</a>
</li>
</ul>
</div>
</div>
</aside>
Loading…
Cancel
Save