在 pythonanywhere 中点击提交后我的 csv 文件没有更新

问题描述 投票:0回答:1

我已经使用 pythonanywhere.com 部署了我的 Flask 程序 这是一份申请表 当我使用空闲运行它时,提交的详细信息会在 csv 文件中更新 但使用 pythonanywhere 运行时它不会更新

这是flask_app.py文件

from flask import Flask,render_template, request, url_for
import csv
app = Flask(__name__, template_folder='templates')

# Session configuration

def csv_appender(student_data):
    with open('Application_Details.csv','a+',newline='\n') as csv_file:
        writer_csv=csv.writer(csv_file)
        writer_csv.writerow(student_data)

@app.route("/",methods=['GET','POST'])
def home():
    if request.method=='POST':
        NameofChild=request.form.get('NameofChild')
        Gender=request.form.get('Gender')
        DOB=request.form.get('DOB')
        StaffChild=request.form.get('StaffChild')
        MotherTongue=request.form.get('MotherTongue')
        Religion=request.form.get('Religion')
        Caste=request.form.get('Caste')
        Nationality=request.form.get('Nationality')
        AadhaarNo=request.form.get('AadhaarNo')
        EMISorSATS=request.form.get('EMISorSATS')
        AdmissionClass=request.form.get('AdmissionClass')
        SchoolLastAttended=request.form.get('SchoolLastAttended')
        LastClassAttended=request.form.get('LastClassAttended')
        MediumOfInstruction=request.form.get('MediumOfInstruction')
        SecondLanguage=request.form.get('SecondLanguage')
        ThirdLanguage=request.form.get('ThirdLanguage')
        MotherName=request.form.get('MotherName')
        FatherName=request.form.get('FatherName')
        MotherMobile=request.form.get('MotherMobile')
        FatherMobile=request.form.get('FatherMobile')
        MotherEmail=request.form.get('MotherEmail')
        FatherEmail=request.form.get('FatherEmail')
        MotherAadhaar=request.form.get('MotherAadhaar')
        FatherAadhaar=request.form.get('FatherAadhaar')
        MotherOccupation=request.form.get('MotherOccupation')
        FatherOccupation=request.form.get('FatherOccupation')
        MotherDesignation=request.form.get('MotherDesignation')
        FatherDesignation=request.form.get('FatherDesignation')
        MotherOrganisation=request.form.get('MotherOrganisation')
        FatherOrganisation=request.form.get('FatherOrganisation')
        MotherOfficeAddress=request.form.get('MotherOfficeAddress')
        FatherOfficeAddress=request.form.get('FatherOfficeAddress')
        MotherAnnualSalary=request.form.get('MotherAnnualSalary')
        FatherAnnualSalary=request.form.get('FatherAnnualSalary')
        MaritalStatus=request.form.get('MaritalStatus')
        ResidentialAddress=request.form.get('ResidentialAddress')
        PINCode=request.form.get('PINCode')
        City=request.form.get('City')
        State=request.form.get('State')
        ResidentialPhoneNo=request.form.get('ResidentialPhoneNo')
        EmergencyPhoneNo=request.form.get('EmergencyPhoneNo')
        CommunicationEmail=request.form.get('CommunicationEmail')
        KnowAboutSchool=request.form.get('KnowAboutSchool')
        Distance=request.form.get('Distance')
        ModeOfTransport=request.form.get('ModeOfTransport')
        AnyAilment=request.form.get('AnyAilment')
        Ailment=request.form.get('Ailment')
        SiblingInSchool=request.form.get('SiblingInSchool')
        S1Name=request.form.get('S1Name')
        S1Age=request.form.get('S1Age')
        S1Gender=request.form.get('S1Gender')
        S1Class=request.form.get('S1Class')
        S1USN=request.form.get('S1USN')
        S2Name=request.form.get('S2Name')
        S2Age=request.form.get('S2Age')
        S2Gender=request.form.get('S2Gender')
        S2Class=request.form.get('S2Class')
        S2USN=request.form.get('S2USN')
        S3Name=request.form.get('S3Name')
        S3Age=request.form.get('S3Age')
        S3Gender=request.form.get('S3Gender')
        S3Class=request.form.get('S3Class')
        S3USN=request.form.get('S3USN')
        S4Name=request.form.get('S4Name')
        S4Age=request.form.get('S4Age')
        S4Gender=request.form.get('S4Gender')
        S4Class=request.form.get('S4Class')
        S4USN=request.form.get('S4USN')
        csv_appender([NameofChild, Gender, DOB, StaffChild, MotherTongue, Religion, Caste, Nationality, AadhaarNo, EMISorSATS, AdmissionClass, SchoolLastAttended, LastClassAttended, 'English', SecondLanguage, ThirdLanguage, MotherName, FatherName, MotherMobile, FatherMobile, MotherEmail, FatherEmail, MotherAadhaar, FatherAadhaar, MotherOccupation, FatherOccupation, MotherDesignation, FatherDesignation, MotherOrganisation, FatherOrganisation, MotherOfficeAddress, FatherOfficeAddress, MotherAnnualSalary, FatherAnnualSalary, MaritalStatus, ResidentialAddress, PINCode, City, State, ResidentialPhoneNo, EmergencyPhoneNo, CommunicationEmail, KnowAboutSchool, Distance, ModeOfTransport, AnyAilment, Ailment, SiblingInSchool, S1Name, S1Age, S1Gender, S1Class, S1USN, S2Name, S2Age, S2Gender, S2Class, S2USN,S3Name,S3Age, S3Gender, S3Class, S3USN, S4Name, S4Age, S4Gender, S4Class, S4USN])
        return render_template('submitted.html')
    return render_template('start.html')

if __name__=='__main__':
    app.run(debug=False,host='0.0.0.0')
    #from waitress import serve
    #serve(app,host='0.0.0.0',port=8080)s

目录 ->

我应该怎么做才能更新?

csv flask deployment pythonanywhere
1个回答
0
投票

所以我发现了错误 pythonanywhere 试图在 mysite 文件夹所在的文件夹中查找 csv 文件

它基本上在那里创建了 csv 文件并将数据存储在该文件中,而不是将其保存在位于 mysite 文件夹内的原始文件中

我只是删除了我创建的原始文件,然后将标题添加到 pythonanywhere 创建的 csv 文件中

© www.soinside.com 2019 - 2024. All rights reserved.