热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何使用Django和Python清除一些警告消息

如何解决《如何使用Django和Python清除一些警告消息》经验,为你挑选了1个好方法。

我需要一些帮助.在运行我的代码时我收到了一些警告pylint,我需要解决这些问题.我在下面解释我的代码.

W: 11, 0: String statement has no effect (pointless-string-statement)
C: 15, 4: Missing method docstring (missing-docstring)
R: 15, 4: Method could be a function (no-self-use)
W: 18, 4: String statement has no effect (pointless-string-statement)
C: 19, 4: Missing method docstring (missing-docstring)
E: 21,11: Instance of 'UserCreationForm' has no 'is_valid' member (no-member)
R: 19, 4: Method could be a function (no-self-use)
C: 28, 4: Missing method docstring (missing-docstring)
R: 28, 4: Method could be a function (no-self-use)
W: 31, 4: String statement has no effect (pointless-string-statement)
C: 32, 4: Missing method docstring (missing-docstring)
E: 34,11: Instance of 'AuthenticationForm' has no 'is_valid' member (no-member)
R: 32, 4: Method could be a function (no-self-use)
C: 38, 0: Missing function docstring (missing-docstring)
W: 41, 0: String statement has no effect (pointless-string-statement)
C: 43, 0: Missing function docstring (missing-docstring)
C: 72, 0: Missing function docstring (missing-docstring)
W: 75, 0: String statement has no effect (pointless-string-statement)
C: 77, 0: Missing function docstring (missing-docstring)
W: 98, 0: String statement has no effect (pointless-string-statement)
C:100, 0: Missing function docstring (missing-docstring)

我的python文件如下.

views.py:

""" coding: utf-8 """
from __future__ import unicode_literals
from django.shortcuts import render, redirect
from django.contrib.auth import login
from django.views.generic import View
from django.contrib.auth.forms import (UserCreationForm, AuthenticationForm)
from lxml import etree
import random
import xml.dom.minidom as m

""" this class is used for user signup """

class Signup(View):
    """ this function used to get the sign up form """
    def get(self, request):
        form = UserCreationForm()
        return render(request, 'booking/signup.html', {'form': form})
    """ this function used for post the sign up data """
    def post(self, request):
        form = UserCreationForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('login')


class AuthLogin(View):
    """ this function used to get the login form """
    def get(self, request):
        form = AuthenticationForm()
        return render(request, 'booking/login.html', {'form': form})
    """ this function used for post the login data """
    def post(self, request):
        form = AuthenticationForm(None, request.POST or None)
        if form.is_valid():
            login(request, form.get_user())
        return redirect('/')

def bmr(request):
    return render(request, 'booking/bmr.html', {})

""" this function is used for save all the data """

def insert(request):
    if request.method == 'POST':
        location_name = request.POST.get('lname')
        rname = request.POST.get('rname')
        seat = request.POST.get('seat')
        projector = request.POST.get('projector')
        video = request.POST.get('video')
        num = str(random.randint(100000000000, 999999999999))
        location_name = location_name[0:255]
        rname = rname[0:255]
        seat = seat[0:10]
        doc = m.parse("roomlist.xml")
        valeurs = doc.getElementsByTagName("roomlist")[0]
        element = doc.createElement("location")
        element.setAttribute("name", location_name)
        el1 = element.appendChild(doc.createElement("room"))
        el1.setAttribute("id", num)
        el2 = el1.appendChild(doc.createElement("roomname"))
        el2.appendChild(doc.createTextNode(rname))
        el3 = el1.appendChild(doc.createElement("noseats"))
        el3.appendChild(doc.createTextNode(seat))
        el4 = el1.appendChild(doc.createElement("projectorscreen"))
        el4.appendChild(doc.createTextNode(projector))
        el5 = el1.appendChild(doc.createElement("videoconf"))
        el5.appendChild(doc.createTextNode(video))
        valeurs.appendChild(element)
        doc.writexml(open("roomlist.xml", "w"))
    return render(request, 'booking/bmr.html', {})

def home(request):
    return render(request, 'booking/home.html', {})

""" This function is used for disply all the data """

def view_book(request):
    doc = m.parse("roomlist.xml")
    staffs = doc.getElementsByTagName("location")
    root = []
    for staff in staffs:
        lname = staff.getAttribute("name")
        roomname = staff.getElementsByTagName(
            "roomname")[0].firstChild.nodeValue
        seat = staff.getElementsByTagName("noseats")[0].firstChild.nodeValue
        project = staff.getElementsByTagName(
            "projectorscreen")[0].firstChild.nodeValue
        video = staff.getElementsByTagName("videoconf")[0].firstChild.nodeValue
        root.append(
            {'lname': lname,
             'roomname': roomname,
             'seat': seat,
             'project': project,
             'video': video})
    return render(request, 'booking/view_book.html', {'people': root})


""" This function is used to sear the data as per room name """

def search(request):
    per = []
    if request.method == 'POST':
        rname = request.POST.get('rname')
        tree = etree.parse('roomlist.xml')
        result = tree.xpath(".//roomname[text()=$rmname]/./..", rmname=rname)
        for user in result:
            per.append(
                {'roomname': user.find('roomname').text,
                 'seat': user.find('noseats').text,
                 'project': user.find('projectorscreen').text,
                 'video': user.find('videoconf').text})
    return render(request, 'booking/home.html', {'people': per})

在这里,我需要关闭最大警告消息,以便评级上升.请做必要的帮助.



1> e4c5..:

这是一个简单的修复.你的doc字符串放错了地方.他们看起来应该更像这样:

class Signup(View):
    """ this class is used for user signup """

    def get(self, request):
        """ this class is used for user signup """
        form = UserCreationForm()
        return render(request, 'booking/signup.html', {'form': form})

    def post(self, request):
        """ this function used for post the sign up data """
        form = UserCreationForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('login')

E:34,11:'AuthenticationForm'实例没有'is_valid'成员(无成员)

至于这一个,pylint显然是错误的(当然假设你AuthenticationForm是一个sublcass forms.Form)

R:28,4:方法可以是一个函数(非自用)

如果您对此感到疑惑,那么pylint认为get并且post不应该是方法Signup.那是因为您没有使用self所需的参数作为类中任何方法的第一个参数.但是pylint再一次显然是错误的,因为基于类的视图就像这样工作.您可能想要为django自定义pylint安装.或者添加这个

def get(self, request):  #pylint disable=no-self-use


推荐阅读
  • 如何自行分析定位SAP BSP错误
    The“BSPtag”Imentionedintheblogtitlemeansforexamplethetagchtmlb:configCelleratorbelowwhichi ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • 在Android开发中,使用Picasso库可以实现对网络图片的等比例缩放。本文介绍了使用Picasso库进行图片缩放的方法,并提供了具体的代码实现。通过获取图片的宽高,计算目标宽度和高度,并创建新图实现等比例缩放。 ... [详细]
  • Spring源码解密之默认标签的解析方式分析
    本文分析了Spring源码解密中默认标签的解析方式。通过对命名空间的判断,区分默认命名空间和自定义命名空间,并采用不同的解析方式。其中,bean标签的解析最为复杂和重要。 ... [详细]
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • JDK源码学习之HashTable(附带面试题)的学习笔记
    本文介绍了JDK源码学习之HashTable(附带面试题)的学习笔记,包括HashTable的定义、数据类型、与HashMap的关系和区别。文章提供了干货,并附带了其他相关主题的学习笔记。 ... [详细]
  • 欢乐的票圈重构之旅——RecyclerView的头尾布局增加
    项目重构的Git地址:https:github.comrazerdpFriendCircletreemain-dev项目同步更新的文集:http:www.jianshu.comno ... [详细]
  • 后台获取视图对应的字符串
    1.帮助类后台获取视图对应的字符串publicclassViewHelper{将View输出为字符串(注:不会执行对应的ac ... [详细]
  • 标题: ... [详细]
  • ASP.NET2.0数据教程之十四:使用FormView的模板
    本文介绍了在ASP.NET 2.0中使用FormView控件来实现自定义的显示外观,与GridView和DetailsView不同,FormView使用模板来呈现,可以实现不规则的外观呈现。同时还介绍了TemplateField的用法和FormView与DetailsView的区别。 ... [详细]
  • 本文讨论了Kotlin中扩展函数的一些惯用用法以及其合理性。作者认为在某些情况下,定义扩展函数没有意义,但官方的编码约定支持这种方式。文章还介绍了在类之外定义扩展函数的具体用法,并讨论了避免使用扩展函数的边缘情况。作者提出了对于扩展函数的合理性的质疑,并给出了自己的反驳。最后,文章强调了在编写Kotlin代码时可以自由地使用扩展函数的重要性。 ... [详细]
  • 重入锁(ReentrantLock)学习及实现原理
    本文介绍了重入锁(ReentrantLock)的学习及实现原理。在学习synchronized的基础上,重入锁提供了更多的灵活性和功能。文章详细介绍了重入锁的特性、使用方法和实现原理,并提供了类图和测试代码供读者参考。重入锁支持重入和公平与非公平两种实现方式,通过对比和分析,读者可以更好地理解和应用重入锁。 ... [详细]
  • 本文整理了Java面试中常见的问题及相关概念的解析,包括HashMap中为什么重写equals还要重写hashcode、map的分类和常见情况、final关键字的用法、Synchronized和lock的区别、volatile的介绍、Syncronized锁的作用、构造函数和构造函数重载的概念、方法覆盖和方法重载的区别、反射获取和设置对象私有字段的值的方法、通过反射创建对象的方式以及内部类的详解。 ... [详细]
author-avatar
我的惟一fd
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有