这是我在Rest Framework中要做的第一项任务,我参考了一个视频教程来做到这一点,这就是为什么即使我从视频中完全复制了代码,序列化程序中的validate方法也无法正常工作的原因。 下面是我的查看功能:
function ClearRange() {
//replace 'Sheet1' with your actual sheet name
var sheet = SpreadsheetApp.getActiveSpreadsheet()
//Inserts a row before populating it
sheet.insertRowAfter(37);
//the next three lines copy a preformatted line and paste it underneath
var source_range = sheet.getRange("A37:V37");
var target_range = sheet.getRange("A38:V38");
source_range.copyTo(target_range);
logData();
//the next lines clear the data form ready for new input
sheet.getRange('B5:D5').clearContent();
sheet.getRange('I5:O5').clearContent();
sheet.getRange('B11:G11').clearContent();
sheet.getRange('I11:P11').clearContent();
sheet.getRange('B18:D18').clearContent();
sheet.getRange('I18:K18').clearContent();
sheet.getRange('B24:F24').clearContent();
sheet.getRange('I24:M24').clearContent();
sheet.getRange('B31:G31').clearContent();
sheet.getRange('K28:Q28').clearContent();
}
function logData() {
// This will take the submitted data and put it into the proper row format
//This bit defines the destination cells
var sheet = SpreadsheetApp.getActiveSheet();
var thedateCell = sheet.getRange("A38");
var QuoteNoCell = sheet.getRange("B38")
var ClientCell = sheet.getRange("C38");
var ContactCell = sheet.getRange("E38");
var AddressCell = sheet.getRange("F38");
var QTOPDCell = sheet.getRange("N38");
var QMBSCell = sheet.getRange("O38");
var QCADDCell = sheet.getRange("P38");
var QTRAVDCell = sheet.getRange("Q38");
var QSODCell = sheet.getRange("R38");
//This bit defines the origin cells
var theDate = sheet.getRange("I28").getValue();
var QuoteNo = sheet.getRange("J28").getValue();
var Client = sheet.getRange("K28").getValue();
var Contact = sheet.getRange("L28").getValue();
var Address = sheet.getRange("M28").getValue();
var QTOPD = sheet.getRange("O19").getValue();
var QMBS = sheet.getRange("P19").getValue();
var QCADD = sheet.getRange("S19").getValue();
var QTRAVD = sheet.getRange("R19").getValue();
var QSOD = sheet.getRange("Q19").getValue();
//This bit transfers the data
thedateCell.setValue(theDate);
QuoteNoCell.setValue(QuoteNo);
ClientCell.setValue(Client);
ContactCell.setValue(Contact);
AddressCell.setValue(Address);
QTOPDCell.setValue(QTOPD);
QMBSCell.setValue(QMBS);
QCADDCell.setValue(QCADD);
QTRAVDCell.setValue(QTRAVD);
QSODCell.setValue(QSOD);
}
function increment() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getRange('J28');
sheet.setValue(Number(sheet.getValue()) + 1)
}
和我的序列化器:
UserLoginSerializer类(ModelSerializer):
class UserLoginAPIView(APIView):
permission_classes = [AllowAny]
serializer_class = UserLoginSerializer
def post(self, request, *args, **kwargs):
data = request.data
serializer = UserLoginSerializer(data=data)
if serializer.is_valid(raise_exception=True):
new_data = serializer.data
return Response(new_data, status=HTTP_200_OK) //I'm getting this response
return Response(serializer.errors, status=HTTP_400_BAD_REQUEST)
由于validate方法的第一行未执行,我如何获得响应(200_OK)?请帮助我。
答案 0 :(得分:1)
哦,这只是一个愚蠢的语法错误。我的validate方法应该在UserLoginSerializer类中,而不在Meta类中。