Suyash
Suyash

Reputation: 51

How do I display data from MongoDB in an HTML page?

Django Version - 1.10.5 I have uploaded the file on MongoDB, with a few fields like e-mail, employee_id and of course the file from an HTML page. I can see it in mongoDB. What I want to do is retrieve the data on an another HTML page using one of those fields(for example putting in a email id that was used to upload the article will give the entire article on the same HTML page.) . How do I go around that?

Upvotes: 0

Views: 1073

Answers (1)

reachhharman
reachhharman

Reputation: 51

From my understanding of the question, current state is:

  • You have imported data to MongoDB
  • You want to retrieve some data into HTML

I didn't understand where you are stuck and hence simple steps would be to create your models.py file defining the fields that you mentioned, email_id, employee_id, etc. Check details on how

Django models API lets you create, retrieve, update and delete objects. Next topic in this documentation page.

I recommend reading through Django documentation thoroughly and trying out things in a demo app from here - Django Models and Databases

Extra: You could use raw SQL queries if you used SQL based DB. But Django quotes:

You should be very careful whenever you write raw SQL. Every time you use it, you should properly escape any parameters that the user can control by using params in order to protect against SQL injection attacks. Please read more about SQL injection protection.

Upvotes: 1

Related Questions