python - parsing of xml to mysql database -


in app,i including function called xml parsing.i trying data data xml file , save mysql database.

i coded google engine,but required data's not saving in database.i can run app without error.

please see codes below

views.py

def goodsdetails(request):     path = "{0}shop.xml".format(settings.project_root)     xmldoc = open(path, 'r')     xmldocdata = xmldoc.read()     xmldoctree = etree.xml(xmldocdata)      items in xmldoctree.iter('item'):         item_id = items[0].text     customername = items[1].text         itemname = items[2].text         location = items[3].text         rate = items[4].text                 shop=shop.objects.create(item_id=item_id,customername=customername,             itemname=itemname,location=location,rate=rate)         shop.save()   shops = shop.objects.all()     context={'shops':shops}     return render(request,'index.html', context) 

i using above logic save data in database xml file.i not getting error not saving database

expected answers welcome.

*update:*i updated code,really xml data gets saved in db,but while displaying same getting following traceback

integrityerror @ / (1062, "duplicate entry '101' key 'primary'") 

thanks

shop.objects.get loads data database. want create data, calling shop(item_id=item_id,customername=customername, itemname=itemname,location=location,rate=rate) , shop.save().

if want update data, need this:

shop = shop.objects.get(tem_id=item_id) shop.customername = customername ...etc... shop.save() 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -