How to fetch data from sql server and display on django web pages

125 views
Skip to first unread message

Amit Kadivar

unread,
Feb 11, 2018, 12:37:28 AM2/11/18
to Django users
Please Help me.
How to fetch data from sql server and display them on django web pages through nginx web server..



PASCUAL Eric

unread,
Feb 11, 2018, 4:59:54 AM2/11/18
to Django users

Hi Amit,


There is no "Django Web page" as you write in your message, but Web pages of the application built on top of the Django framework. Hence how to display data depends on how the Web pages of *your* application are designed.


Second point, one of the roles of Django is to isolate the application developer from the raw SQL requests needed to store and retrieve data from the underlying data base. This is called an ORM (object relational mapping) and it is one of the keystones of the Django framework. The benefit from this is that you don't have to deal with SQL requests (at least for the vast majority of the situations), but to specify the data model of the application as a collection of classes and relations between them. Django tools will take care of creating the relational database first, and then translate under the hood the object oriented interactions you make with your model into the corresponding SQL requests.


I've the feeling that you have not fully understood what Django is, what Django does and how to write a Django application. So, take no offense, but have you read (and understood) at least the introduction (including tutorials) documentation of Django ?


What is exactly the context of your project, what is it supposed to do,... ? The way you are presenting it, it sounds a bit like a student homework. Maybe it's not, but...


Best regards.


Eric

From: django...@googlegroups.com <django...@googlegroups.com> on behalf of Amit Kadivar <amit.k...@gmail.com>
Sent: Sunday, February 11, 2018 6:37:28 AM
To: Django users
Subject: How to fetch data from sql server and display on django web pages
 
Please Help me.
How to fetch data from sql server and display them on django web pages through nginx web server..



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b5577524-e67d-465f-bb49-e54bca92c88b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

carlos

unread,
Feb 11, 2018, 12:41:28 PM2/11/18
to django...@googlegroups.com

On Sun, Feb 11, 2018 at 3:58 AM, PASCUAL Eric <eric.p...@cstb.fr> wrote:

Hi Amit,


There is no "Django Web page" as you write in your message, but Web pages of the application built on top of the Django framework. Hence how to display data depends on how the Web pages of *your* application are designed.


Second point, one of the roles of Django is to isolate the application developer from the raw SQL requests needed to store and retrieve data from the underlying data base. This is called an ORM (object relational mapping) and it is one of the keystones of the Django framework. The benefit from this is that you don't have to deal with SQL requests (at least for the vast majority of the situations), but to specify the data model of the application as a collection of classes and relations between them. Django tools will take care of creating the relational database first, and then translate under the hood the object oriented interactions you make with your model into the corresponding SQL requests.


I've the feeling that you have not fully understood what Django is, what Django does and how to write a Django application. So, take no offense, but have you read (and understood) at least the introduction (including tutorials) documentation of Django ?


What is exactly the context of your project, what is it supposed to do,... ? The way you are presenting it, it sounds a bit like a student homework. Maybe it's not, but...


Best regards.


Eric

From: django...@googlegroups.com <django...@googlegroups.com> on behalf of Amit Kadivar <amit.k...@gmail.com>
Sent: Sunday, February 11, 2018 6:37:28 AM
To: Django users
Subject: How to fetch data from sql server and display on django web pages
 
Please Help me.
How to fetch data from sql server and display them on django web pages through nginx web server..



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

For more options, visit https://groups.google.com/d/optout.



--
att.
Carlos Rocha

sum abiut

unread,
Feb 12, 2018, 4:26:14 PM2/12/18
to django...@googlegroups.com

You may want to check out sqlalchemy they provide a pretty good documentation on what you are aftering http://docs.sqlalchemy.org/en/latest/dialects/mssql.html

From you view you can defile a function like so.

view.py

from sqlalchemy import*
from django.shortcuts import render

def connectto_db(request):
    engine=create_engine('mssql+pymssql://username:password@servername /Ddabname')
    connection=engine.connect()
    metadata=MetaData()


    table=Table('tablename',metadata,autoload=True,autoload_with=engine)
    stmt='SELECT * FROM table'
    results=connection.execute(stmt).fetchall()
    return render(request,'template.html',locals())


then  you can pass the results to your template.html

Hope this helps.

Cheers

On Sun, Feb 11, 2018 at 4:37 PM, Amit Kadivar <amit.k...@gmail.com> wrote:
Please Help me.
How to fetch data from sql server and display them on django web pages through nginx web server..



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b5577524-e67d-465f-bb49-e54bca92c88b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

PASCUAL Eric

unread,
Feb 13, 2018, 7:33:00 AM2/13/18
to django...@googlegroups.com

Hi,


> You may want to check out sqlalchemy they provide a pretty good documentation on what you are aftering


For my understanding, why are you suggesting to use SQLAlchemy while Django provides an ORM out of the box ?


SQLAlchemy is required for frameworks such as Flask, which do nothing with respect to the data layer, but it's not clear which benefit it could bring here.


Best regards


Eric

From: django...@googlegroups.com <django...@googlegroups.com> on behalf of sum abiut <sua...@gmail.com>
Sent: Monday, February 12, 2018 10:24:07 PM
To: django...@googlegroups.com
Subject: Re: How to fetch data from sql server and display on django web pages
 
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages