Skip to content

Instantly share code, notes, and snippets.

@josejaguirre
Last active September 25, 2017 13:11
Show Gist options
  • Save josejaguirre/8cafd8818eea2659e3e9c250a3344128 to your computer and use it in GitHub Desktop.
Save josejaguirre/8cafd8818eea2659e3e9c250a3344128 to your computer and use it in GitHub Desktop.
Cadena de conexión para Flask & SQL Alchemy
import urllib
import pyodbc
from flask import Flask, request, jsonify
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
# Cadena de conexión
string_connection = "DRIVER={SQL Server};Database=DATABASE_NAME;SERVER=SERVER_NAME;UID=USER;PWD=PASSWORD"
string_connection = urllib.parse.quote_plus(string_connection)
string_connection = "mssql+pyodbc:///?odbc_connect=%s" % string_connection
app.config["SQLALCHEMY_DATABASE_URI"] = string_connection
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = True
db = SQLAlchemy(app)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment