Saturday, July 7, 2012

Re: submit parameters to py script

On Sat, 7 Jul 2012 05:09:54 -0700, Smaran Harihar
<smaran.harihar@gmail.com> declaimed the following in
gmane.comp.python.django.user:

>
> 1. My settings.py points to Postgres database, which is my main database.
> 2. The data I wish to extract and display in CSV, is in another database
> (mysql). What I have come to know after completing the basic tutorials of
> Django is that we define the database in the settings.py and since I
> already have the postgres defined, how can I also connect to this MySql
> Database, using views/models? This is why I wanted to trigger an external
> py script which will deal with this MySql database separately.
>
If that external script was going to use plain SQL access (MySQLdb),
there is no excuse for making it external... The Django application
logic could do direct MySQLdb calls for connection/retrieval/etc.

If the plan was to have the external script initialize a Django app
(using model definitions and Django's ORM), the invocation would have to
be similar to how the main Django process is getting invoked (which may
require creating a pseudo-HTTP request -- or at least the environment of
one, to pass to the external script for processing; and then retrieving
the response data) {Heck, this might almost be implemented by making the
external script an independent Django site, setting the access to
internal [localhost], and using Python's url library to "get" the needed
page from the independent Django site, then use an HTML parser to
extract the returned data -- if you embed special markers you might be
able to just copy the HTML directly into the template of the response to
the user}

In either event -- consider the overhead involved in starting up an
external python script on each invocation.

However, that is all moot... read:
https://docs.djangoproject.com/en/dev/topics/db/multi-db/



> Is there a way to connect to multiple databases simultaneously? If so then
> please let me know how?
>
> Thanks,
> Smaran
>
> On Sat, Jul 7, 2012 at 4:01 AM, Melvyn Sopacua <m.r.sopacua@gmail.com>wrote:
>
> > On 7-7-2012 11:44, Smaran Harihar wrote:
> > > Thanks for the reply Melvyn and Babatunde. So my script is, using the
> > > parameters, to search in a database and then spitting out the output back
> > > as CSV.
> >
> > This only makes sense in the django world, if your script is accessing a
> > database that is not part of the application itself. For example an
> > accounting program in django that replaces a firms older software.
> > Access to previous years is then provided via a script that simply
> > provides CSV format so data can be entered into a spreadsheet program
> > and reports can be created. One would use this approach if converting
> > the old data to the new application consumes too many resources for the
> > few times the data will be used.
> >
> > I can't think of many other cases where I would use this approach, so ...
> >
> > > Ok, so adding it to view makes more sense, but how do i connect or
> > execute
> > > that view, on the click of the submit button??
> >
> > The key question is if you have models for the tables in this database?
> > If so your best option is to translate the parameters to django's
> > queryset syntax. If you don't understand what that means, you're
> > probably new to django and we'll try to be more verbose.
> >
> > As a side note, especially when new to django but not unfamiliar with
> > webdevelopment/databases, you need to learn to let go of your SQL
> > knowledge and start thinking in models and querysets. Once you fully
> > understand how this works and what you can do with it, you can apply
> > your SQL knowledge to optimize what django's syncdb has created for you
> > or even start working the other way around using inspectdb.
> > --
> > Melvyn Sopacua
> >
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-users@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscribe@googlegroups.com.
> > For more options, visit this group at
> > http://groups.google.com/group/django-users?hl=en.
> >
> >
>
>
> --
> Thanks & Regards
> Smaran Harihar
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate