2
我需要一些幫助。我在使用pylint
運行代碼時遇到了一些警告,我需要解決這些問題。我在下面解釋我的代碼。如何使用Django和Python清除一些警告消息
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})
在這裏,我需要關閉最大警告消息,以便進行評分起來。請做必要的幫助。