from django.shortcuts import render,redirect
from blog import models
from django.contrib.auth.models import User
from django.contrib.auth import authenticate,login,logout
# Create your views here.
def index(request):
articles_list = models.article.objects.all()
return render(request,'blog/index.html',locals())
def article(request,id):
artc = models.article.objects.get(id=id)
return render(request,'blog/article.html',locals())
def logins(request):
if request.method == 'POST':
username = request.POST.get("username")
password = request.POST.get("password")
user = authenticate(username=username,password=password)
if user:
login(request,user)
return redirect('/blog/index')
else:
msg = '用户名或密码错误!'
return render(request,'blog/login.html',locals())
return render(request,'blog/login.html')
def regist(request):
if request.method == 'POST':
username = request.POST.get("username")
password = request.POST.get("password")
password2 = request.POST.get("password2")
email = request.POST.get("email")
if password != password2:
msg = '两次输入的密码不一样!'
return render(request,'blog/regist.html',locals())
elif username == '':
msg = '用户名不能为空'
return render(request,'blog/regist.html',locals())
cusor = User.objects.create_user(username=username,password=password,email=email)
cusor.save()
return redirect('/blog/login')
return render(request,'blog/regist.html')
def log_out(request):
logout(request)
return redirect('/blog/')
pro/urls.py
"""test1 URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path,include
from test1 import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
# path('',include('booktest.urls')),
path('blog/',include('blog.urls')),
]
urlpatterns += static(settings.MEDIA_URL,document_root = settings.MEDIA_ROOT)
我们都晓得java实现线程2种方式,一个是继承Thread,另一个是实现Runnable。
模拟窗口买票,第一例子继承thread,代码如下
package thread;
public class ThreadTest {
public static void main(String[] args) {
Thread1 t1 = new Thread1(
#include<iostream>
using namespace std;
//辅助函数,交换两数之值
template<class T>
void mySwap(T &x, T &y){
T temp = x;
x = y;
y = temp;
}
const int size = 10;
//一、用直接插入排
对日期类型的数据进行序列化和反序列化时,需要考虑如下问题:
1. 序列化时,Date对象序列化的字符串日期格式如何
2. 反序列化时,把日期字符串序列化为Date对象,也需要考虑日期格式问题
3. Date A -> str -> Date B,A和B对象是否equals
默认序列化和反序列化
import com
1. DStream的类说明文档:
/**
* A Discretized Stream (DStream), the basic abstraction in Spark Streaming, is a continuous
* sequence of RDDs (of the same type) representing a continuous st
ReplayingDecoder是FrameDecoder的子类,不熟悉FrameDecoder的,可以先看看
http://bylijinnan.iteye.com/blog/1982618
API说,ReplayingDecoder简化了操作,比如:
FrameDecoder在decode时,需要判断数据是否接收完全:
public class IntegerH
1.js中用正则表达式 过滤特殊字符, 校验所有输入域是否含有特殊符号function stripscript(s) { var pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~!@#¥……&*()——|{}【】‘;:”“'。,、?]"
经常在写shell脚本时,会碰到要以另外一个用户来执行相关命令,其方法简单记下:
1、执行单个命令:su - user -c "command"
如:下面命令是以test用户在/data目录下创建test123目录
[root@slave19 /data]# su - test -c "mkdir /data/test123"