0

I need to store my html form data in XML file save that file inside same project using Django. I am providing my code below:

insert.html:

<form method="post" action=" " onSubmit="return validateForm();" name="frmfeed">
    {% csrf_token %}
    <label>Name: </label>
    <input name="name" value="{{person.name}}">
    <br>
    <label>Phone: </label>
    <input name="phone" value="{{person.phone}}">
    <br>
    <label>Age: </label>
    <input type="number" name="age" value="{{person.age}}">
    <br>
    <input type="hidden" name="id" value="{{person.id}}">
    <input type="submit" value="Submit">
</form>

view.py:

def insert(request): 
    # If this is a post request we insert the person 

Here I need when user will submit the form the data will store in a xml file and format is given below.

<user>
  <name="Ram">
    <user id='12345'>
     <phone>9937229867</phone>
     <age>32</age>
   </user>
  </name>
</user>

I need to store in the above format.

halfer
  • 19,824
  • 17
  • 99
  • 186
satya
  • 3,508
  • 11
  • 50
  • 130
  • Are you asking how to process the form data or how to parse the xml, or both? For just parsing the xml you can use the standard library, following question has a couple of good examples: https://stackoverflow.com/questions/3605680/creating-a-simple-xml-file-using-python – Maarten Jun 14 '17 at 13:38
  • I need to save data into xml file instead of database. – satya Jun 14 '17 at 13:43
  • You could save it as a `TextField` – Brobin Jun 14 '17 at 13:47
  • @satya may be helpful https://stackoverflow.com/questions/3605680/creating-a-simple-xml-file-using-python – Anup Jun 14 '17 at 14:42

0 Answers0