User Interface Using Django

Author: Priyanka Nemana





Introduction:

Django is a python based web framework. We can make dynamic web pages easily using django. As it is a python based web framework we can integrate python codes with the frontend and obtain desired outputs easily.


Django is compatible with snowflake as we can access snowflake tables using python-snowflake connector.


We can showcase tableau dashboards in the user interface using html script.


Django follows model- template-views architecture. We can create front end using html, javascript,css, bootstrap etc.



Django and Snowflake:

By importing the snowflake-python connector module we can connect to snowflake and execute sql commands in the python code.


Connection code:


ctx = snowflake.connector.connect

(

user='ENTER USERNAME',

password='ENTER PASSWORD',

account='ENTER IDENTIFIER',

warehouse='YOUR WAREHOUSE',

database='DATABASE IN USE',

schema='SCHEMA IN USE',

role = 'ROLE IN USE'

)


After connection is successful we can execute queries, for example:

cur = ctx.cursor()

sql = "YOUR QUERY"

cur.execute(sql)


Django and Frontend:

We can develop the frontend using html, css, javascript and also bootstrap by integrating them with python code.


Django and Tableau:

By adding a script of html code we can showcase tableau dashboards.


Sample script:

<div class='tableauPlaceholder' id='viz1653555156309' style='position: relative'><noscript><a href='#'><img alt='Sheet 19 ' src='https:&#47;&#47;public.tableau.com&#47;static&#47;images&#47;Bo&#47;Book2_16517645606150&#47;Sheet19&#47;1_rss.png' style='border: none' /></a></noscript><object class='tableauViz' style='display:none;'><param name='host_url' value='https%3A%2F%2Fpublic.tableau.com%2F' /> <param name='embed_code_version' value='3' /> <param name='site_root' value='' /><param name='name' value='Book2_16517645606150&#47;Sheet19' /><param name='tabs' value='no' /><param name='toolbar' value='yes' /><param name='static_image' value='https:&#47;&#47;public.tableau.com&#47;static&#47;images&#47;Bo&#47;Book2_16517645606150&#47;Sheet19&#47;1.png' /> <param name='animate_transition' value='yes' /><param name='display_static_image' value='yes' /><param name='display_spinner' value='yes' /><param name='display_overlay' value='yes' /><param name='display_count' value='yes' /><param name='language' value='en-US' /></object></div> <script type='text/javascript'>

var divElement = document.getElementById('viz1653555156309');

var vizElement = divElement.getElementsByTagName('object')[0]; vizElement.style.width='100%';vizElement.style.height=(divElement.offsetWidth*0.75)+'px'; var scriptElement = document.createElement('script'); scriptElement.src = 'https://public.tableau.com/javascripts/api/viz_v1.js'; vizElement.parentNode.insertBefore(scriptElement, vizElement); </script>


Result:


Conclusion:

With the help of DJANGO we can integrate snowflake and can retrieve data from our warehouses easily and can also showcase Tableau dashboards in the User Interface. We can create dynamic websites using Django by including HTML,CSS, BOOSTRAP codes.


References:

1. For snowflake integration with python: https://youtu.be/i2V9HotNgvA


2. For tableau integration : https://youtu.be/wJ2CHIJalNU




53 views0 comments

Recent Posts

See All