diff --git a/article/templatetags/__pycache__/timetonow.cpython-36.pyc b/article/templatetags/__pycache__/timetonow.cpython-36.pyc
index 593a633..0a68eb1 100644
Binary files a/article/templatetags/__pycache__/timetonow.cpython-36.pyc and b/article/templatetags/__pycache__/timetonow.cpython-36.pyc differ
diff --git a/article/templatetags/timetonow.py b/article/templatetags/timetonow.py
index 6b4f233..3a9b93b 100644
--- a/article/templatetags/timetonow.py
+++ b/article/templatetags/timetonow.py
@@ -13,13 +13,14 @@ def timetonow(value):
now = timezone.now()
now = now.replace(tzinfo=None)
delta = now-valuetime
- s = delta.seconds
+
+ s = delta.total_seconds()
if s>86400:
return '%d天前' % (int(s/86400))
elif s>3600:
return '%d小时前' % (int(s/3600))
elif s>120:
- return '%d分钟前' % (int(s/120))
+ return '%d分钟前' % (int(s/60))
else:
return '刚刚'
diff --git a/db.sqlite3 b/db.sqlite3
index d6fba15..ed0d3e9 100644
Binary files a/db.sqlite3 and b/db.sqlite3 differ
diff --git a/edconline/__pycache__/settings.cpython-36.pyc b/edconline/__pycache__/settings.cpython-36.pyc
index 3001fda..abc3031 100644
Binary files a/edconline/__pycache__/settings.cpython-36.pyc and b/edconline/__pycache__/settings.cpython-36.pyc differ
diff --git a/edconline/__pycache__/urls.cpython-36.pyc b/edconline/__pycache__/urls.cpython-36.pyc
index 27e4383..a0736df 100644
Binary files a/edconline/__pycache__/urls.cpython-36.pyc and b/edconline/__pycache__/urls.cpython-36.pyc differ
diff --git a/edconline/__pycache__/views.cpython-36.pyc b/edconline/__pycache__/views.cpython-36.pyc
index 03e0260..6bed60e 100644
Binary files a/edconline/__pycache__/views.cpython-36.pyc and b/edconline/__pycache__/views.cpython-36.pyc differ
diff --git a/edconline/urls.py b/edconline/urls.py
index 0834bf3..203d844 100644
--- a/edconline/urls.py
+++ b/edconline/urls.py
@@ -35,4 +35,5 @@
path('tinymce/', include('tinymce.urls')),
path('article/', include('article.urls')),
path('userpage/', include('userpage.urls')),
+ path('utils/', include('utils.urls')),
]
diff --git a/edconline/views.py b/edconline/views.py
index 1144c72..b697538 100644
--- a/edconline/views.py
+++ b/edconline/views.py
@@ -8,6 +8,7 @@
import userpage
from . import globalarg
+
# Create your views here.
def homepage(request):
@@ -33,3 +34,10 @@ def homepage(request):
return render(request,'index.html',{'cover':cover,'arts':arts})
+
+
+
+
+
+
+
diff --git a/static/fonts/Monaco.ttf b/static/fonts/Monaco.ttf
new file mode 100644
index 0000000..57217b3
Binary files /dev/null and b/static/fonts/Monaco.ttf differ
diff --git a/static/upload/church_JNMUCQr.jpg b/static/upload/church_JNMUCQr.jpg
new file mode 100644
index 0000000..510f991
Binary files /dev/null and b/static/upload/church_JNMUCQr.jpg differ
diff --git a/templates/index.html b/templates/index.html
index f37882e..064de59 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -34,7 +34,7 @@
{% if title %}{{title}}{% endif %}
{{i.readtime}}
- {{i.tag}}
+ {% if i.tag %}{{i.tag}}{% endif %}
阅读全文
diff --git a/userpage/__pycache__/forms.cpython-36.pyc b/userpage/__pycache__/forms.cpython-36.pyc
new file mode 100644
index 0000000..4be9639
Binary files /dev/null and b/userpage/__pycache__/forms.cpython-36.pyc differ
diff --git a/userpage/__pycache__/urls.cpython-36.pyc b/userpage/__pycache__/urls.cpython-36.pyc
index 33b830c..69fdf70 100644
Binary files a/userpage/__pycache__/urls.cpython-36.pyc and b/userpage/__pycache__/urls.cpython-36.pyc differ
diff --git a/userpage/__pycache__/views.cpython-36.pyc b/userpage/__pycache__/views.cpython-36.pyc
index c9d7c82..1569d5d 100644
Binary files a/userpage/__pycache__/views.cpython-36.pyc and b/userpage/__pycache__/views.cpython-36.pyc differ
diff --git a/userpage/forms.py b/userpage/forms.py
new file mode 100644
index 0000000..3b89968
--- /dev/null
+++ b/userpage/forms.py
@@ -0,0 +1,80 @@
+from django.core.exceptions import ValidationError
+from django import forms
+from django.forms import fields
+from django.forms import widgets
+from django.core.validators import RegexValidator
+from django.contrib.auth.models import User
+
+
+class RegisterForm(forms.Form):
+ username = fields.CharField(
+ required=True,
+ widget=widgets.TextInput(attrs={'class': "form-control",'placeholder': '用户名为8-12个字符'}),
+ min_length=6,
+ max_length=12,
+ strip=True,
+ error_messages={'required': '标题不能为空',
+ 'min_length': '用户名最少为6个字符',
+ 'max_length': '用户名最不超过为20个字符'},
+ )
+ email = fields.EmailField(
+ required=True,
+ widget=widgets.TextInput(attrs={'class': "form-control",'placeholder': '请输入邮箱'}),
+ #strip=True,
+ error_messages={'required': '邮箱不能为空',
+ 'invalid':'请输入正确的邮箱格式'}
+ )
+ pwd = fields.CharField(
+ widget=widgets.PasswordInput(attrs={'class': "form-control",'placeholder': '请输入密码,必须包含数字,字母,特殊字符'},render_value=True),
+ required=True,
+ min_length=6,
+ max_length=12,
+ strip=True,
+ validators=[
+ # 下面的正则内容一目了然,我就不注释了
+ RegexValidator(r'((?=.*\d))^.{6,12}$', '必须包含数字'),
+ RegexValidator(r'((?=.*[a-zA-Z]))^.{6,12}$', '必须包含字母'),
+ RegexValidator(r'((?=.*[^a-zA-Z0-9]))^.{6,12}$', '必须包含特殊字符'),
+ RegexValidator(r'^.(\S){6,10}$', '密码不能包含空白字符'),
+ ], #用于对密码的正则验证
+ error_messages={'required': '密码不能为空!',
+ 'min_length': '密码最少为6个字符',
+ 'max_length': '密码最多不超过为12个字符!',},
+ )
+ pwd_again = fields.CharField(
+ #render_value会对于PasswordInput,错误是否清空密码输入框内容,默认为清除,我改为不清楚
+ widget=widgets.PasswordInput(attrs={'class': "form-control",'placeholder': '请再次输入密码!'},render_value=True),
+ required=True,
+ strip=True,
+ error_messages={'required': '请再次输入密码!',}
+
+ )
+
+ def clean_username(self):
+ # 对username的扩展验证,查找用户是否已经存在
+ username = self.cleaned_data.get('username')
+ users = User.objects.filter(username=username).count()
+ if users:
+ raise ValidationError('用户已经存在!')
+ return username
+
+ def clean_email(self):
+ # 对email的扩展验证,查找用户是否已经存在
+ email = self.cleaned_data.get('email')
+ email_count = User.objects.filter(email=email).count() #从数据库中查找是否用户已经存在
+ if email_count:
+ raise ValidationError('该邮箱已经注册!')
+ return email
+
+ def _clean_new_password2(self): #查看两次密码是否一致
+ password1 = self.cleaned_data.get('pwd')
+ password2 = self.cleaned_data.get('pwd_again')
+ if password1 and password2:
+ if password1 != password2:
+ # self.error_dict['pwd_again'] = '两次密码不匹配'
+ raise ValidationError('两次密码不匹配!')
+
+ def clean(self):
+ #是基于form对象的验证,字段全部验证通过会调用clean函数进行验证
+ self._clean_new_password2() #简单的调用而已
+
diff --git a/userpage/templates/userpage/login.html b/userpage/templates/userpage/login.html
new file mode 100644
index 0000000..c91c0ca
--- /dev/null
+++ b/userpage/templates/userpage/login.html
@@ -0,0 +1,68 @@
+{% extends 'base.html' %}
+{% load timetonow %}
+
+{% block header %}
+ 物志 › 登录
+{% endblock %}
+
+{% block banner %}
+
+{% endblock %}
+
+{% block content %}
+
+
+
+ {% if errors %}
+ {% for error in errors %}
+
+ {% endfor %}
+ {% endif %}
+
+
+{% endblock %}
\ No newline at end of file
diff --git a/userpage/templates/userpage/profile.html b/userpage/templates/userpage/profile.html
index 64ef98a..0ba5cb3 100644
--- a/userpage/templates/userpage/profile.html
+++ b/userpage/templates/userpage/profile.html
@@ -35,7 +35,6 @@
{% endfor %}
{% endif %}
-
{% endblock %}
{% block banner %}
@@ -128,6 +127,7 @@
{% ifequal member.id user.id %}
{# 消息提醒 #}
+
{% for i in notice %}
{{i.comment.user}} 在 {{i.comment.article}} 的评论中提到了您 {{i.comment_time|timetonow}}
diff --git a/userpage/urls.py b/userpage/urls.py index 69c7369..e7b111b 100644 --- a/userpage/urls.py +++ b/userpage/urls.py @@ -4,5 +4,7 @@ urlpatterns = [ path('member/