top of page

User Interface Using Django

Updated: Mar 15

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 front end 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 a 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 the 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 front end 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 Eableau 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




347 views0 comments
bottom of page