报错,贴图整理(1)

这里是getElementByTagName("div")=============单复数的问题,给element加上s就可以了,仅仅是一个"s"的问题,把s加上就可以解决了.

 

 

在js中我们要想改变属性的值,在console里面可以直接操作,在改变之前我们需要找到标签,然后才能改,在找标签的过程中我们需要找到具体的标签进行修改,不能找到一个标签数组去改

 

egon 博客练习题: http://www.cnblogs.com/linhaifeng/articles/7267596.html#_label5

第24题:

这里的in出错了,在mysql里面暂时还不支持limit里面有子查询的in/all/any/some方法

 

 

 

 

在html文档中,使用bootstrap工具的时候,遇到的问题:

这里是出错的部分,用红色圈出来了

 

这里是已经改正过了的,注意细节,两张图片对比出来就是一个空格的问题,就差在一个空格上

 

 

 

在django项目里面我们的函数体,跟数据库连接的时候,报错,这里的原因是比较简单的,把相关的代码缩进到for循环里面即可,一个tab键就可以搞定的,下面的变量预警是因为他们是在for循环里面被定义的,然后我们却在for循环外面使用它了,局部命名空间的变量是不能够被全局所使用的,这里是命名空间的部分出错了

 

 

这里是HTML标签里面的属性有缺失导致页面无法显示出预期的效果

这里这张图的重点是method="post",我们的form表单里面需要进行一些增删改查的操作固定要有这个method这个属性,并且要根据不同的动作有不同的改变,

 

 

模态框的标签是需要写作body的直系子标签的,要紧贴着,不能够有间隙,隔一层都不可以,

如图所示,位置没有关系,放到前面或者后面或者中间都可以的,只要紧贴着body即可,也就是我们模态框最外层的那个div标签需要贴着左边的代码框,贴着,即可

 

这里我们我的开始符号和结束符号位置需要和我们的/对应上,结束符放到我们的/外面然后再''的里面

 

 

这里我们的引号里面,不能够加上/不能够加上/,不能够加上/, 就如图下所示,按照下面的图片写即可

 

 这里我们的get和filter得到的数据类型是不一样的,get是得到一个对象,而我们的filter是得到一个列表,列表取值是需要使用索引的 ,而我们的对象是可以直接去取值的

 

django项目里面的标点符号问题,如果没有给我们提示的话我们就不要擅自加上空格了

 

这里的报错是我们的django项目里面csrf中间件的问题:

 

解决办法:

 

 

 

我们的django项目里面,使用orm的时候,在python console里面,查询的时候要想显示sql语句要设置logging,然后在python console里面我们就可以得到查询的SQL语句了,

这里的logging参数配置里面的version参数需要使用小写,如果是大写的"VERSION"的话就会报错,我们的django项目都无法运行

 

 

 

我们找bug的时候要按照顺序来一层一层分析,先从url开始入手,然后到views函数,再到前端模板,按照顺序过一遍,不要死盯着一处去看,要着眼于多处,才有更多可能去发现问题,我们要一步一步去分析报错的原因,才能找到根源,而不是陷在一个地方,思维方式还是很重要的,否则就是过分的浪费时间,

路由系统:

 url(r'^selog/', include(seurl)),  # 这里是路由分发

# 这是子路由
from django.conf.urls import url
from session import views as sesviews

urlpatterns = [
    url(r"^login/", sesviews.login, name='sesslogin'),
    # url(r'^home/$', sesviews.home, name='home'),
    url(r'^home/$', sesviews.home, name='home'),
    url(r"^index/$", sesviews.index, name='index'),
    url(r'^logout/$', sesviews.logout, name='logout'),
    url(r'^gettest/$', sesviews.gettest,),

    url(r'^login3/$', sesviews.LoginView.as_view()),
    url(r'^index3/$', sesviews.IndexView.as_view()),

    url(r'^login2/$', sesviews.login2,),
    url(r'^index2/$', sesviews.index2,),

]

 

 

视图函数:

from django.shortcuts import render, HttpResponse, redirect
from functools import wraps
from django.urls import reverse
# Create your views here.


# 简单的原始版装饰器
def wrapper(func):
    @wraps(func)
    def inner(request, *args, **kwargs):
        cookie_k = request.get_signed_cookie('who', None, salt='s8',max_age=5)  # 我们这里的参数who设置的它,后面获取的时候也是要通过它去获取,否则参数匹配不上
# 页面是无法出来效果的
        print(11111, cookie_k)
        if cookie_k:
            # 如果我们检测到有cookie,就证明是我们自己的用户,
            # ret = func(request, *args, **kwargs)
            ret = func(request, *args, **kwargs)
            return ret
        else:
            # 反之,如果没有检测到,就不是我们的用户,需要登录或者注册
            # return redirect('sebog/login/')
            next_url = request.get_full_path()
            print(next_url,"-------")
            return redirect('/selog/login/?next={}'.format(next_url))
            # 我们这里是路由分发的,所以需要在url里面加上前缀否则是无法得到地址的
    return inner

#http://127.0.0.1:8000/selog/login/?next=home
def login(request):
    if request.method == 'POST':
        user = request.POST.get("user")
        pwd = request.POST.get('pwd')
        if user == 'alex' and pwd == "123":
            next_url = request.GET.get('next', None)
            print(next_url)
            if next_url:
                rep = redirect(next_url)
            else:
                # rep = redirect(reverse('index'))
                rep = redirect('/selog/index/')
            # return redirect('home')
            rep.set_signed_cookie('who', user, salt='s8')  # 我们的cookie失效时间不能太短了,否则我们还没有把url输入到浏览器cookie就已经失效了
            return rep
    return render(request, 'session/login.html')


def logout(request):
    rep = redirect(reverse('sesslogin'))
    rep.delete_cookie('who')
    return rep


@wrapper
def index(request):
    cookie_k = request.get_signed_cookie('who', None, salt='s8')
    if cookie_k:
        # return redirect(reverse('sesslogin'))
        return render(request, 'session/index.html')
    else:
        return redirect(reverse('sesslogin'))
        # return render(request, 'session/index.html')


@wrapper
def home(request):
    return render(request, 'session/home.html')


@wrapper
def gettest(request):
    print(request.GET.get('next'))
    return HttpResponse('OK')

 

前端模板:

home

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Title</title>
</head>
<body>
<h1>welcome home</h1>

<button type="submit" value="put on"><a href="{% url 'logout' %}">quit</a></button>
</body>
</html>

 

index:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Title</title>
</head>
<body>
<h1>there is index page</h1>
<button type="submit" value="put on"><a href="{% url 'logout' %}">quit</a></button>
</body>
</html>

 

login:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Title</title>
</head>
<body>

<form action="{{ request.get_full_path }}" method="post">
{#<form action="/login/" method="post">#}
{#<form action="{% url 'sesslogin' %}" method="post">#}
    {% csrf_token %}
    <input type="text" name="user" placeholder="user">
    <input type="password" name="pwd" placeholder="pwd">
    <input type="submit" value="put in">

</form>
</body>
</html>

 

 

我们的console里面的500错误:

 

 

 

 

这个场景是在我们的flask里面的redis连接池里写投票系统遇到的bug

 

 redis.exceptions.ResponseError: WRONGTYPE Operation against a key holding the wrong kind of value

这里是中文翻译:

 [redis.exceptions.ResponseError:WRONGTYPE针对持有错误类型值的键的操作]

我们的这个键hell在redis里面已经做为其他的数据的键了,就不能再被重用了,换一个键的名字即可(会出现这个原因是因为我一开始用的redis,然后又在原有基础上进行了redis连接池的转换,所以我们的代码块都没有变,那么就是我们的redis里面的lpush里面的键是重复了,所以就会报这个错,)

{原来的redis里面的key对应的数据类型不一致,key对应的数据类型一致的话,是可以插入的}

 

 

ajax报错:“parsererror”

 这里是解析错误,后端传过来的数据没有做格式处理才会这样,需要去后端看最后返回的数据格式跟ajax里面的数据格式是否匹配,我这里ajax是用的json数据类型,后端传的是字符串没有做json。dump()的处理,我把字符串进行了dump之后就可以正常调用前端ajax的success函数了。

 

执行pip install pipreqs报错:

 error: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/docopt.py'

    

是权限不够,被拒绝下载,我在命令前加上了sudo 就可以了,

即:

sudo pip install pipreqs

(报错信息很长一大串,我一时心急就把一大串都粘到搜索框去搜,结果肯定是搜不出来啊,后来慢慢理出头绪,找到了error这一行,以后遇到报错,要能分辨哪里是核心点,这样就会省很多力气,找到突破口快速解决问题)

 

 

Can't connect to local MySQL server through socket '/tmp/mysql.sock' 

mysql预警信息解决方案:

 

python3.6 + Django2.1 + ajax

排错了一整天,没有遇到过这样的错误,连把错误信息拿到网上都搜不到一星半点线索。。。。。。

一开始自己一个人写前后端,出现跨域,然后在中间件里面加上了请求头信息

['Access-Control-Allow-Origin'] = '*'
["Access-Control-Allow-Methods"] = "POST,GET,OPTION,PUT,DELETE,PATCH"

与此同时,前端没怎么写过,就连ajax的路由写法都是现查的,然后就随便找了一篇博客没有细看,粗暴的写成了这样:“http://127.0.0.1:8000/login/”

然后在本地测试的时候,一切如常,于是推到服务器的时候,就开始报错,报同样的错,如下贴出, 

报错信息如下:


[DEBUG][2019-03-28 15:13:47,575][base.py:872]Exception while resolving variable 'name' in template 'unknown'.

Traceback (most recent call last):
  File "/root/.virtualenvs/dream_envir/lib/python3.5/site-packages/django/template/base.py", line 829, in _resolve_lookup
    current = current[bit]
TypeError: 'URLResolver' object is not subscriptable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/root/.virtualenvs/dream_envir/lib/python3.5/site-packages/django/template/base.py", line 837, in _resolve_lookup
    current = getattr(current, bit)
AttributeError: 'URLResolver' object has no attribute 'name'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/root/.virtualenvs/dream_envir/lib/python3.5/site-packages/django/template/base.py", line 843, in _resolve_lookup
    current = current[int(bit)]
ValueError: invalid literal for int() with base 10: 'name'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/root/.virtualenvs/dream_envir/lib/python3.5/site-packages/django/template/base.py", line 850, in _resolve_lookup
    (bit, current))  # missing attribute
django.template.base.VariableDoesNotExist: Failed lookup for key [name] in <URLResolver <URLPattern list> (admin:admin) 'admin/'>

 

上面有关键字信息可以捕捉到,admin,URL,

一开始测试的时候就没有考虑admin,也没有想过URL会有问题,于是一直很困惑问题出在哪里,本地和线上测试结果差太多,一直以为是线上环境的其他细节有问题,于是耽误了大把的时间。

仔细查过了Django2.0以及ajax的URL路由写法,发现ajax路由写死了,所以线上报错;

试过了admin无法打开页面,也是报上面同样的错,把上面处理跨域的中间件注释掉用另一个方式解决跨域。问题就解决啦啦啦

 

 

mongo  服务启动报错:

 

用命令:mongod

错误信息如下:

2019-04-08T17:26:11.722+0800 I CONTROL  [initandlisten] MongoDB starting : pid=6463 port=27017 dbpath=/data/db 64-bit host=dream-macdeMBP.lan
2019-04-08T17:26:11.726+0800 I CONTROL  [initandlisten] db version v3.4.2
2019-04-08T17:26:11.726+0800 I CONTROL  [initandlisten] git version: 3f76e40c105fc223b3e5aac3e20dcd026b83b38b
2019-04-08T17:26:11.726+0800 I CONTROL  [initandlisten] allocator: system
2019-04-08T17:26:11.726+0800 I CONTROL  [initandlisten] modules: none
2019-04-08T17:26:11.726+0800 I CONTROL  [initandlisten] build environment:
2019-04-08T17:26:11.726+0800 I CONTROL  [initandlisten]     distarch: x86_64
2019-04-08T17:26:11.726+0800 I CONTROL  [initandlisten]     target_arch: x86_64
2019-04-08T17:26:11.727+0800 I CONTROL  [initandlisten] options: {}
2019-04-08T17:26:11.728+0800 I -        [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2019-04-08T17:26:11.728+0800 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=3584M,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2019-04-08T17:26:11.735+0800 E STORAGE  [initandlisten] WiredTiger error (13) [1554715571:735657][6463:0x1144e05c0], file:WiredTiger.wt, connection: /data/db/WiredTiger.turtle: handle-open: open: Permission denied
2019-04-08T17:26:11.751+0800 I -        [initandlisten] Assertion: 28595:13: Permission denied src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp 267
2019-04-08T17:26:11.753+0800 I STORAGE  [initandlisten] exception in initAndListen: 28595 13: Permission denied, terminating
2019-04-08T17:26:11.753+0800 I NETWORK  [initandlisten] shutdown: going to close listening sockets...
2019-04-08T17:26:11.753+0800 I NETWORK  [initandlisten] removing socket file: /tmp/mongodb-27017.sock
2019-04-08T17:26:11.753+0800 I NETWORK  [initandlisten] shutdown: going to flush diaglog...
2019-04-08T17:26:11.753+0800 I CONTROL  [initandlisten] now exiting
2019-04-08T17:26:11.753+0800 I CONTROL  [initandlisten] shutting down with code:100

 

用命令: mongo

错误如下:

MongoDB shell version v3.4.2
connecting to: mongodb://127.0.0.1:27017
2019-04-08T17:26:54.606+0800 W NETWORK  [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2019-04-08T17:26:54.609+0800 E QUERY    [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:237:13
@(connect):1:6
exception: connect failed

 

解决方法:

进入mongo安装目录:

cd /usr/local/mongodb/bin/

 

执行命令:

sudo ./mongod

 

如下提示:

 
Password:
2019-04-08T18:26:09.128+0800 I CONTROL  [initandlisten] MongoDB starting : pid=6693 port=27017 dbpath=/data/db 64-bit host=dream-macdeMBP.lan
2019-04-08T18:26:09.128+0800 I CONTROL  [initandlisten] db version v3.4.2
2019-04-08T18:26:09.128+0800 I CONTROL  [initandlisten] git version: 3f76e40c105fc223b3e5aac3e20dcd026b83b38b
2019-04-08T18:26:09.128+0800 I CONTROL  [initandlisten] allocator: system
2019-04-08T18:26:09.128+0800 I CONTROL  [initandlisten] modules: none
2019-04-08T18:26:09.128+0800 I CONTROL  [initandlisten] build environment:
2019-04-08T18:26:09.128+0800 I CONTROL  [initandlisten]     distarch: x86_64
2019-04-08T18:26:09.128+0800 I CONTROL  [initandlisten]     target_arch: x86_64
2019-04-08T18:26:09.128+0800 I CONTROL  [initandlisten] options: {}
2019-04-08T18:26:09.129+0800 I -        [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2019-04-08T18:26:09.129+0800 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=3584M,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2019-04-08T18:26:09.411+0800 I CONTROL  [initandlisten]
2019-04-08T18:26:09.411+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-04-08T18:26:09.411+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2019-04-08T18:26:09.411+0800 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2019-04-08T18:26:09.411+0800 I CONTROL  [initandlisten]
2019-04-08T18:26:09.420+0800 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
2019-04-08T18:26:09.420+0800 I NETWORK  [thread1] waiting for connections on port 27017
2019-04-08T18:26:46.084+0800 I NETWORK  [thread1] connection accepted from 127.0.0.1:57474 #1 (1 connection now open)

 

出现字样

waiting for connections on port 27017

即是服务启动了,查看进程可以看到mongo进程

ps -ef|grep mongod


0 6692 2600 0 6:26PM ttys001 0:00.06 sudo ./mongod
0 6693 6692 0 6:26PM ttys001 0:00.41 ./mongod
501 6705 5153 0 6:26PM ttys002 0:00.01 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn mongod

 

然后再开一个窗口,进入mongo

mongo   # 这行命令是安装mongo的时候把环境配置好了,才能执行它




MongoDB shell version v3.4.2
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.2
Server has startup warnings:
2019-04-08T18:26:09.411+0800 I CONTROL [initandlisten]
2019-04-08T18:26:09.411+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-04-08T18:26:09.411+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2019-04-08T18:26:09.411+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2019-04-08T18:26:09.411+0800 I CONTROL [initandlisten]
> use test
switched to db test

 

 

...................持续更新中.................................

posted @ 2017-12-28 20:56  dream-子皿  阅读(331)  评论(0编辑  收藏  举报