Hi,

For simplicity and reliability, although a hair slower, it probably makes 
sense to create a new database connection during each request.

You could define a function that gets a database connection with your 
parameters and then call that at the top of each view.

Collin

On Thursday, November 20, 2014 1:59:04 PM UTC-5, Ankit Arora wrote:
>
> I'm working with a Postgresql database with Django. Because of licensing 
> reasons, I can't use psycopg2 , so I'm using the alternative pygresql.
>
> I don't need to use the Django ORM at all, I simply need the cursor for 
> cur.execute() and cur.fetchall().
>
> Since pygresql doesn't have a Django backend connector, I can't use the 
> pygresql pgdb module in the Database settings in settings.py; I've to 
> manually open up a connection object.
>
> What would be the best practice to do this? Currently I've simply created 
> the connection object conn=pgdb.connect(params) in views.py outside of 
> all functions, but this seems a bit hacky and I do get 'ProgrammingError: 
> Server Closed the connection unexpectedly' errors here and there.
>
> One approach might be to simply create an executeQuery() function which 
> Opens a connection, executes a query, and closes it each time I want to 
> execute a query. But I'm not sure if that's best practice and whether it 
> would cause any issues.
>
> Any tips?
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/26cf0a67-9eec-479f-9513-fa941e2f3306%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to