Running django on demand via my PyQt4 Standalone app

289 views
Skip to first unread message

Dam ian

unread,
Oct 24, 2016, 7:14:52 AM10/24/16
to Django users
Hi,

I work on some Smart Home UI / Controlling system using PyQt4, now I'm in the point where i need a Web Server to share a "Admin Page" to let the user change some Smart Home settings (via web page of course :p ). I searched the internet for a answer / idea and I think that the django server would be the best solution, e.g. like django my "APP" also use a SQLite DB. I need that the server is running only if the user activate the "Admin Mode" and want do some change to the UI / App and only locally.

unfortunately i still learning python and my knowledge is not on the level to do this in the right way and I thought, that maybe someone of you can help me:


Q1: Is it good idea to start a new QThread who runs the script os.system("web/manage.py runserver")?
Q2: If yes - how can i stop the server - maybe through terminating the QThread?
Q3: If no - what is the best method to start a django server on demand via my PyQt4 App and to stop it?
Q4: can i share my DB whit django, is this a good idea?
Q5: can i access from django server my app components class, variable etc. and vice versa ( if the server is running)?
Q6: can u point me where i can find some documentation or example to get closer to my goal?


i know there many ways how to do this ( or not) but I would like to achieve it via the "pythonic way" / best practices
if someone from you can hep me I would be very grateful

Cheers Damian

PS. Sorry for my not best english

Avraham Serour

unread,
Oct 24, 2016, 2:31:07 PM10/24/16
to django-users
Q1: Is it good idea to start a new QThread who runs the script os.system("web/manage.py runserver")?
No, don't do that.

Q3: If no - what is the best method to start a django server on demand via my PyQt4 App and to stop it?
If the idea is to use django from within a desktop app, you don't need a webserver at all, just import whatever model, view or method you wish to call and call it, no need to go through all the http stack.

Q4: can i share my DB whit django, is this a good idea?
I'm not sure what you mean by this, but one of the features of storing data in a DB as opposed to storing in a file is that multiple users/apps can access it, well even if you were storing everything in a file you could still share it, but then you would need to handle everything yourself.

Q5: can i access from django server my app components class, variable etc. and vice versa ( if the server is running)?
Why not? Did you try? Did you encounter an error?

Q6: can u point me where i can find some documentation or example to get closer to my goal?
Did you went through the django tutorial?

I'm taking a wild guess here and guessing that you would want an ORM to use from your desktop app to access the database, defining python classes and models.
Django is a webframework, but it is not an all or nothing thing, you don't need to use everything, you may just use the ORM, define your models, import them from your application.
As an alternative you may also take a look at sqlalchemy

(I realize that saying "Taking a guess and guessing" is probably not valid english, but is should be. If anyone cares to rephrase that I won't take offence)

Avraham


--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f45e774a-5284-4078-92b2-8813deb9ddd8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Vinicius Assef

unread,
Oct 24, 2016, 5:14:40 PM10/24/16
to django...@googlegroups.com
On 24 October 2016 at 16:30, Avraham Serour <tov...@gmail.com> wrote:
>
> Django is a webframework, but it is not an all or nothing thing, you don't
> need to use everything, you may just use the ORM, define your models, import
> them from your application.

This is an interesting scenario, Avraham.

I can't imagine how settings.py would be called to configure database
stuff. Could you?

It made me curious about that.

--
Vinicius Assef

Gergely Polonkai

unread,
Oct 24, 2016, 5:39:40 PM10/24/16
to django...@googlegroups.com

Hello,

I think installing Django purely for its ORM is a huge overkill. Why not, for example, SQLAlchemy? Or Qt's own DB layer (I'm making an educated guess here; if GTK has one, maybe Qt has its own, too.)

If you actually want to use the web framework functionality, though, that's another story, but that requires a web view in your desktop app. I'm not sure that's the way I'd go unless the web front-end is already working (in which case why bother making a desktop app?)

Best,
Gergely


--
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...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Avraham Serour

unread,
Oct 24, 2016, 7:03:09 PM10/24/16
to django-users

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Vinicius Assef

unread,
Oct 25, 2016, 6:26:49 AM10/25/16
to django...@googlegroups.com
Absolutely! :-D

Thank you.

On 24 October 2016 at 21:01, Avraham Serour <tov...@gmail.com> wrote:
> does this help?
>
> https://docs.djangoproject.com/en/1.10/topics/settings/#calling-django-setup-is-required-for-standalone-django-usage
>
>
> On Tue, Oct 25, 2016 at 12:13 AM, Vinicius Assef <vinic...@gmail.com>
> wrote:
>>
>> On 24 October 2016 at 16:30, Avraham Serour <tov...@gmail.com> wrote:
>> >
>> > Django is a webframework, but it is not an all or nothing thing, you
>> > don't
>> > need to use everything, you may just use the ORM, define your models,
>> > import
>> > them from your application.
>>
>> This is an interesting scenario, Avraham.
>>
>> I can't imagine how settings.py would be called to configure database
>> stuff. Could you?
>>
>> It made me curious about that.
>>
>> --
>> Vinicius Assef
>>
>> --
>> 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...@googlegroups.com.
>> To post to this group, send email to django...@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAFmXjSCZua21SHr9GWTLvAU1iAqfqN70rG7Jq07o98Y_zQU89w%40mail.gmail.com.
>> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> 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...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAFWa6tJi2b-URgFzymfWwXZCG%2BbD-10E2S8wmO6pzaLBU25cpw%40mail.gmail.com.

Mario R. Osorio

unread,
Oct 25, 2016, 10:17:12 AM10/25/16
to Django users
I cannot understand is why would you need django for admin, but use some other standalone (desktop?) application for everything else.  You should try and stay either on the django or on the standalone application.

If after further analysis you still think you need both, then I'd use django, along with a rest api such as Django REST framework (www.django-rest-framework.org) or Tastypie (tastypieapi.org).

You might also ant to make use of kivy (kivy.org) for the user interface.

HTH
Mario Osorio

Dam ian

unread,
Oct 25, 2016, 3:20:29 PM10/25/16
to Django users
Hi again,

and thanks for the answer and Tips 

@Mario R. Osorio 
>I cannot understand is why would you need django for admin, but use some other standalone (desktop?) application for everything else.  You should try and stay either on the django or on the standalone application. 

i think i must add why i need to use a "desktop app" and a web server for the "desktop app" :). The desktop app i need for something like this

for the user to control all devices @home, its a home Automatisation Controlling UI (wirten in PyQt)and second part - the web part (django) i need to setup the whole system, to add new hardware micro controller to customize the whole UI. I could add the whole settings / customizing stuff to the UI but from the user experience side it would not be optimal, u know what i mean? This UI should be only to Control not to setup things.


@all others

now the SQL part in PyQt i do whit QSql and its ok for me,if i use django it's not a problem for me to use only for the web part the django way. 

Why i would use django because in the future i will develop some Smart Phone app to Control the system too and i read that django add automatically some API what make me easier to add the communication between the mobile app and my standalone application


Mario R. Osorio

unread,
Oct 25, 2016, 7:43:26 PM10/25/16
to django-users
I used to do home automation, so I know you need an interface with very high "WOW!" factor AND PORTABILITY. That is why I proposed you check kivy (http://kivy.org). kivy is the kick-ass interface I'd use, bar none.

this of course my opinion and recomendation, but you know YAHOO.



Dtb/Gby
=======
Mario R. Osorio
A.S. of Computer Programming and Analysis

“If I had asked people what they wanted, they would have said faster horses.”
 ― Henry Ford

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/KKWwFzk9Z5U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Dam ian

unread,
Oct 26, 2016, 12:15:56 PM10/26/16
to Django users, ma...@osorio.solutions
yeah you are right with the WoW effect :) and i know this framework but its to complex for me :P i prefere to use PyQt4, for example you have something like QT Designer where you can graphically deploy and customize the whole UI and then convert to pure python, what make me my work easier. If kivy had a usable graphicall editor i think i will choose this framework :) 

Leslie Jeffries

unread,
Oct 27, 2016, 2:45:50 PM10/27/16
to Django users
I have a Django project that is used to view complex data for use by Systems Engineers who are analyzing requirements traceability. Django works great for the viewing of data in lots of differing views. The templating system is awesome for that.

However the data that is being viewed is coming from ugly Excel spreadsheets. So I have several scripts that pull the relevant data from these spreadsheets and use it to create the database for use by Django.

In order to access the models in Django, each of these scripts starts with:

import os
import sys

lib_path = os.path.abspath("[path to Django project]")
sys.path.append(lib_path)

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
import django
django.setup()

from [app].models import L1_requirement, L2_requirement, ...

I can then use the Django methods on my_model.objects to get, filter, save my various requirement models.
Reply all
Reply to author
Forward
0 new messages