Skip to content

Commit

Permalink
python mysql connection
Browse files Browse the repository at this point in the history
  • Loading branch information
sreeharshabalaji committed Dec 4, 2020
1 parent 2331bde commit 6e5d147
Show file tree
Hide file tree
Showing 21 changed files with 47 additions and 11 deletions.
11 changes: 0 additions & 11 deletions server/python_server/connect.py

This file was deleted.

Binary file not shown.
16 changes: 16 additions & 0 deletions server/python_server/database/connect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import os
import mysql.connector
env = os.environ.get("PYTHON_ENV")

def connectSql():
if(env =="production"):
mydb=mysql.connector.connect(host="shoppy-db.cexukr3eruop.ap-south-1.rds.amazonaws.com",user="root",password="shoppy_password",database="shoppy")
else:
mydb=mysql.connector.connect(host="localhost",user="root",password="root",database="shoppy")

return mydb


return mycursor

# mycursor.execute("SELECT * FROM product")
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 3 additions & 0 deletions server/python_server/pages/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
5 changes: 5 additions & 0 deletions server/python_server/pages/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class PagesConfig(AppConfig):
name = 'pages'
Empty file.
Binary file not shown.
4 changes: 4 additions & 0 deletions server/python_server/pages/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from django.db import models

# Create your models here.

3 changes: 3 additions & 0 deletions server/python_server/pages/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
12 changes: 12 additions & 0 deletions server/python_server/pages/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.http import HttpResponse
from django.shortcuts import render
from database import connect

my = connect.connectSql()
mycursor = my.cursor()
data = mycursor.execute("SELECT * FROM shoppy.product")
print(mycursor)
print(data)
# Create your views here.
def home_view(*args,**kwargs):
return HttpResponse ("<h1>hello world</h1>")
Binary file not shown.
Binary file not shown.
Binary file modified server/python_server/python_server/__pycache__/urls.cpython-38.pyc
Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions server/python_server/python_server/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',

'pages',
]

MIDDLEWARE = [
Expand Down
2 changes: 2 additions & 0 deletions server/python_server/python_server/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
"""
from django.contrib import admin
from django.urls import path
from pages import views

urlpatterns = [
path('',views.home_view,name='home'),
path('admin/', admin.site.urls),
]

0 comments on commit 6e5d147

Please sign in to comment.