简体   繁体   中英

Use django to expose python functions on the web

I have not worked with Django seriously and my only experience is the tutorials on their site.

I am trying to write my own application now, and what I want is to have some sort of API. My idea is that I will later be able to use it with a client written in any other language.

I have the simplest of all apps, a model that has a name and surname field.

So the idea is that I can now write an app lets say in c++ that will send two strings to my Django app so they can be saved in the database as name, surname respectively.

What I know until now is to create a form so a user can enter that information, or have the information in the url, and of curse adding them myself from the admin menu.

What I want though is some other better way, maybe creating a packet that contains that data. Later my client sends this data to my Django webpage and it will extract the info and save it as needed. But I do not know how to do this.

If my suggested method is a good idea, then I would like an example of how this is done. If not the I would like suggestions for possible things I could try out.

Typically, as stated by @DanielRoseman, you certainly want to:

  • Create a REST API to get data from another web site
  • Get data, typically in JSON or XML, that will contain all the required data ( name and surname )
  • In the REST controller, Convert this data to the Model and save the Model to the database
  • Send an answer.

More information here: http://www.django-rest-framework.org/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM