Two projects fail to import the same main app when I turn on both in Apache

2015-05-05 Thread Thomas Levine
Hi,

For like the first time ever I want to make complicated websites,
so using Django finally seems like a good idea. And it is! All the
small building blocks that I had never thought of are already here.
Anyway, the part that's relevant to my present concern is that I
haven't deployed Django many times before and thus don't really know
what I'm doing.

I have two sites that I want to host on the same computer.
I have root access on this computer. The two sites are called
"dadaportal", which is on https://thomaslevine.com, and "scott",
which is on http://scott.dada.pink.

I also have a bunch of other sites configured in Apache, but
none of those uses wsgi or even Python.

Both sites work fine if I disable the other. Here is what its
configuration looks like.
http://big.dada.pink/010-dadaportal.conf
http://dada.pink/dadaportal/dadaportal/wsgi.py
http://dada.pink/dadaportal/dadaportal/settings.py

And here is the other.
http://big.dada.pink/015-scott.conf
http://dada.pink/scott2/scott2/wsgi.py
http://dada.pink/scott2/scott2/settings.py

I have problem when I try to run both at the same time.
The 010-dadaportal.conf and 015-scott.conf are in my
/etc/apache2/sites-available directory, so I have been
enabling them and disabling them like this.

  a2dissite 010-dadaportal && a2ensite 015-scott &&
  service apache2 reload && sleep 1s &&
  a2dissite 015-scott && a2ensite 010-dadaportal &&
  service apache2 reload

If I disable both of them and access either one in a web
browser, this shows up in the error log corresponding to
the If I try to access either one.

  [Tue May 05 09:10:14.433772 2015] [wsgi:error] [pid 4155] [remote 
79.136.47.106:512] ImportError: No module named 'dadaportal'

For example, here is a line from /var/log/apache2/scott2-error.log,

  [Tue May 05 09:10:14.433772 2015] [wsgi:error] [pid 4155] [remote 
79.136.47.106:512] ImportError: No module named 'dadaportal'

and here is one from /var/log/apache2/dadaportal-error.log.

  [Tue May 05 09:13:01.552357 2015] [wsgi:error] [pid 4338] [remote 
79.136.47.106:512] ImportError: No module named 'dadaportal'

Note that both projects look for "dadaportal". dadaportal is the
app containing the settings file in the dadaportal project.
http://dada.pink/dadaportal/manage.py

It is not in the scott2 project; I checked by running the following
command from the root of the scott2 project.

  $ grep --include='*.py' -r dadaportal .

It printed nothing. Here are versions of things.

$ pip3 freeze|grep Django
Django==1.8.1
$ python3 --version
Python 3.4.2

Any idea of what I'm doing incorrectly? Thanks

Tom

-- 
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/20150505093246.GA9236%40d1stkfactory.
For more options, visit https://groups.google.com/d/optout.


Re: Two projects fail to import the same main app when I turn on both in Apache

2015-05-07 Thread Thomas Levine
Indeed! Thanks

Tom

On 05 May 13:49, Tom Evans wrote:
> On Tue, May 5, 2015 at 10:32 AM, Thomas Levine <_...@thomaslevine.com> wrote:
> > Hi,
> >
> > For like the first time ever I want to make complicated websites,
> > so using Django finally seems like a good idea. And it is! All the
> > small building blocks that I had never thought of are already here.
> > Anyway, the part that's relevant to my present concern is that I
> > haven't deployed Django many times before and thus don't really know
> > what I'm doing.
> >
> > I have two sites that I want to host on the same computer.
> > I have root access on this computer. The two sites are called
> > "dadaportal", which is on https://thomaslevine.com, and "scott",
> > which is on http://scott.dada.pink.
> >
> > I also have a bunch of other sites configured in Apache, but
> > none of those uses wsgi or even Python.
> >
> > Both sites work fine if I disable the other. Here is what its
> > configuration looks like.
> > http://big.dada.pink/010-dadaportal.conf
> > http://dada.pink/dadaportal/dadaportal/wsgi.py
> > http://dada.pink/dadaportal/dadaportal/settings.py
> >
> > And here is the other.
> > http://big.dada.pink/015-scott.conf
> > http://dada.pink/scott2/scott2/wsgi.py
> > http://dada.pink/scott2/scott2/settings.py
> >
> > I have problem when I try to run both at the same time.
> 
> You're missing the process-group argument from WSGIScriptAlias so it
> tries to run both of them in the default process group.
> 
> https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/modwsgi/#using-mod-wsgi-daemon-mode
> 
> Cheers
> 
> Tom
> 
> -- 
> 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/CAFHbX1%2B7ag9RiJrQ6dUPzADOss5dN2zWxrmpH3zHkF%2BsCP-eNQ%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+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/20150507125652.GA25449%40d1stkfactory.
For more options, visit https://groups.google.com/d/optout.


How do I debug 400 errors that arise from turning off debug mode?

2015-05-07 Thread Thomas Levine
Hi,

Every page on my site returns a status code of 400 when I set
`debug = False` in my settings file, and this doesn't happen
if I switch it to `True`. How can I determine what is going wrong?

I have not managed to find it in the Django loggers (through email
or through a custom logging facility), the console output of the
development server, nor the logs of the production server (Apache).
Well I do see it in the development server output, but only as this:

[07/May/2015 13:38:38]"GET /admin/ HTTP/1.0" 400 0

In case I should be able to find the issue in those places and I
am just doing something wrong, here are my settings.
http://dada.pink/scott2/scott2/settings.py

I believe that neither the `settings.py` nor even `wsgi.py` files
are being run, as adding the following lines to their tops did not
produce `settings.pyabc` nor `wsgi.pyabc`, respectively.

with open(__file__ + 'abc', 'w') as fp:
fp.write('abc')

Thanks

Tom

-- 
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/20150507134350.GA25982%40d1stkfactory.
For more options, visit https://groups.google.com/d/optout.


Re: JSON data

2015-05-07 Thread Thomas Levine
> which part is slow?  the API, the processing of the JSON, or the
> display?

And here's how you can check that. Insert the following line between
the different steps that Tim itemized,

print(time.perf_counter())

subtract the numbers that get printed, and then determine which step
is slow.

Alternatively, if your code is written very cleanly, you can use timeit.
https://docs.python.org/3/library/timeit.html

Tom

-- 
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/20150507135234.GA27152%40d1stkfactory.
For more options, visit https://groups.google.com/d/optout.


Re: Sending Data from client side(another computer) to Django(my computer) using Socket library

2015-05-07 Thread Thomas Levine
On 07 May 16:00, steve malise wrote:
> The error comes when i runserver and send data from another computer to
> django,then i get this "code 400, message Bad request syntax ( data from
> another computer)"

This is because

On 07 May 11:42, Tom Evans wrote:
> Eurgh. Your hand-crafted HTTP request is not a valid request. Use one
> of the http libraries built in to python:

You can find here some directions on forming the request validly, 
http://www.w3.org/Protocols/Specs.html

as you apparently don't want to use any of the libraries below.

On 07 May 16:00, steve malise wrote:
> urllib2:
> https://docs.python.org/2/howto/urllib2.html#data
> 
> httplib:
> https://docs.python.org/2/library/httplib.html#examples
> 
> or use a 3rd party library that wraps those in a more pleasing interface:
> 
> requests:
> http://docs.python-requests.org/en/latest/

Using one of the above-listed libraries would still accomplish what you
are trying to do, as you described here,

On 07 May 16:00, steve malise wrote:
> What i am trying to do is run python script(client side) on another
> computer which is on same network with my computer,then receive data from
> another computer with the django(which is running on my computer(server
> side)).i am using built-in "runserver".

so I suspect that you are doing something more that we missed. Perhaps
you could tell us why you want to do this?

-- 
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/20150507141332.GA27942%40d1stkfactory.
For more options, visit https://groups.google.com/d/optout.


Re: How do I debug 400 errors that arise from turning off debug mode?

2015-05-07 Thread Thomas Levine
Well this is neat. Following the advice of Collin Anderson,
https://groups.google.com/d/msg/django-users/d_aWdw_AhH0/424ABkRajaoJ

I removed the LOGGING stuff, which wasn't that interesting anyway.
And then the exception emails started appearing!

I got this,

> Invalid HTTP_HOST header: 'localhost:8000'. You may need to add
> 'localhost' to ALLOWED_HOSTS.

which was a surprise to me because I already had 'localhost:*' in
my settings, but I switched it and it indeed worked on the development
server. For example, this returned the admin login page.

curl 'http://localhost:8000/admin/login/?next=/admin/'

But it still didn't work with the Apache server. ('scott.dada.pink',
the host that Apache watches for, had always been in ALLOWED_HOSTS.)
So I removed 'localhost' from ALLOWED_HOSTS and tried this.

curl -H 'host: scott.dada.pink' 
'http://localhost:8000/admin/login/?next=/admin/'

It returned the same web page, even though the host was not in
ALLOWED_HOSTS. I guess the development server does not care about
ALLOWED_HOSTS?

curl -H 'host: scott.dada.pink' 
'http://localhost:8000/admin/login/?next=/admin/'

Unfortunately, while email works with the development server,
it does not work on the production server, and I have yet to figure
out why.

On 07 May 13:43, Thomas Levine wrote:
> Hi,
> 
> Every page on my site returns a status code of 400 when I set
> `debug = False` in my settings file, and this doesn't happen
> if I switch it to `True`. How can I determine what is going wrong?
> 
> I have not managed to find it in the Django loggers (through email
> or through a custom logging facility), the console output of the
> development server, nor the logs of the production server (Apache).
> Well I do see it in the development server output, but only as this:
> 
> [07/May/2015 13:38:38]"GET /admin/ HTTP/1.0" 400 0
> 
> In case I should be able to find the issue in those places and I
> am just doing something wrong, here are my settings.
> http://dada.pink/scott2/scott2/settings.py
> 
> I believe that neither the `settings.py` nor even `wsgi.py` files
> are being run, as adding the following lines to their tops did not
> produce `settings.pyabc` nor `wsgi.pyabc`, respectively.
> 
> with open(__file__ + 'abc', 'w') as fp:
> fp.write('abc')
> 
> Thanks
> 
> Tom
> 
> -- 
> 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/20150507134350.GA25982%40d1stkfactory.
> 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+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/20150507181137.GA3658%40d1stkfactory.
For more options, visit https://groups.google.com/d/optout.


Re: Two projects fail to import the same main app when I turn on both in Apache

2015-05-07 Thread Thomas Levine
It turns out that my two inquiries from the past three days were more
related than I had thought. I have finally resolved both.

Let's first review what was going on. Here was my original problem,
titled "Two projects fail to import the same main app when I turn on
both in Apache".

On Tue, May 5, 2015 at 10:32 AM, Thomas Levine <_...@thomaslevine.com> wrote:
> I have two sites that I want to host on the same computer.
> I have root access on this computer. The two sites are called
> "dadaportal", which is on https://thomaslevine.com, and "scott",
> which is on http://scott.dada.pink.
>
> ...
>
> Both sites work fine if I disable the other. Here is what its
> configuration looks like.
>
> I have problem when I try to run both at the same time.

Tom gave me something that seemed to work.

On 05 May 13:49, Tom Evans wrote:
> You're missing the process-group argument from WSGIScriptAlias so it
> tries to run both of them in the default process group.
> 
> https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/modwsgi/#using-mod-wsgi-daemon-mode

After setting the process groups, I stumbled upon another problem,
which I titled "How do I debug 400 errors that arise from turning off
debug mode?"

On 07 May 13:43, Thomas Levine wrote:
> Hi,
> 
> Every page on my site returns a status code of 400 when I set
> `debug = False` in my settings file, and this doesn't happen
> if I switch it to `True`. How can I determine what is going wrong?
> 
> ...
> 
> I believe that neither the `settings.py` nor even `wsgi.py` files
> are being run, as adding the following lines to their tops did not
> produce `settings.pyabc` nor `wsgi.pyabc`, respectively.
> 
> with open(__file__ + 'abc', 'w') as fp:
> fp.write('abc')

I eventually managed to debug it somewhat.

On 07 May 18:11, Thomas Levine wrote:
> Well this is neat. Following the advice of Collin Anderson,
> https://groups.google.com/d/msg/django-users/d_aWdw_AhH0/424ABkRajaoJ
> 
> I removed the LOGGING stuff, which wasn't that interesting anyway.
> And then the exception emails started appearing!
> 
> I got this,
> 
> > Invalid HTTP_HOST header: 'localhost:8000'. You may need to add
> > 'localhost' to ALLOWED_HOSTS.
> 
> which was a surprise to me because I already had 'localhost:*' in
> my settings, but I switched it and it indeed worked on the development
> server. For example, this returned the admin login page.
> 
> curl 'http://localhost:8000/admin/login/?next=/admin/'
> 
> But it still didn't work with the Apache server. ('scott.dada.pink',
> the host that Apache watches for, had always been in ALLOWED_HOSTS.)
> So I removed 'localhost' from ALLOWED_HOSTS and tried this.
> 
> curl -H 'host: scott.dada.pink' 
> 'http://localhost:8000/admin/login/?next=/admin/'
> 
> It returned the same web page, even though the host was not in
> ALLOWED_HOSTS. I guess the development server does not care about
> ALLOWED_HOSTS?
> 
> curl -H 'host: scott.dada.pink' 
> 'http://localhost:8000/admin/login/?next=/admin/'
> 
> Unfortunately, while email works with the development server,
> it does not work on the production server, and I have yet to figure
> out why.

Then I looked at the scott2-error.log log again and noticed this.

[Fri May 08 05:14:05.295576 2015] [wsgi:info] [pid 16576] [remote 
81.234.202.247:15414] mod_wsgi (pid=16576, process='thomaslevine.com', 
application='scott.dada.pink|'): Loading WSGI script 
'/srv/dadaportal/dadaportal/wsgi.py'.

Scott2 is running in the "thomaslevine.com" process group even though
its Apache configuration contains this.

WSGIScriptAlias / /srv/scott2/scott2/wsgi.py process-group=scott.dada.pink

But now I saw the problem! The two sites' configuration files had the
WSGI configuration lines outside of the virtual host,

WSGIScriptAlias / /srv/scott2/scott2/wsgi.py process-group=scott.dada.pink
WSGIDaemonProcess scott.dada.pink python-path=/srv/scott2
WSGIProcessGroup scott.dada.pink


ServerName scott.dada.pink
# ...


making them global. They needed to be inside the virtual host.


WSGIScriptAlias / /srv/scott2/scott2/wsgi.py 
process-group=scott.dada.pink
WSGIDaemonProcess scott.dada.pink python-path=/srv/scott2
WSGIProcessGroup scott.dada.pink

ServerName scott.dada.pink
# ...


When I switch even just one of them to be local, both sites work.
This makes sense to me, as that's how name spaces are.

Before I had done this, Dadaportal was working, and Scott2 wasn't.
I think the r

Re: Django Https issue

2015-05-12 Thread Thomas Levine
I searched the internet for this error message

On 11 May 20:41, zichuanxi...@163.com wrote:
> *use django shell with uwsgi:*
> *I get an error:***
> 
> 

and came across reports like this one.
http://www.xinotes.net/notes/note/628/

On 11 May 20:41, zichuanxi...@163.com wrote:
> Hi guys
> I am using django 1.6 + uwsgi + nginx deploying a web site
> I cant visit https url with urllib2 when i use uwsgi ,  if i dont use uwsgi 
> ,then i can visit https url:

Could it be that you are running different versions of Python with
uwsgi verses without uwsgi? (I'm not entirely sure what you mean by
that, by the way, so it might help to elaborate.)

Try running this in both the uwsgi and non-uwsgi environments.

import sys
print(sys.version)   
print(sys.path)

Any difference in the output between the two versions is very relevant.
And if there is no difference in the output, then I don't know what is
going on.

Tom

-- 
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/20150512110600.GA15050%40d1stkfactory.
For more options, visit https://groups.google.com/d/optout.


How do I display a map with GeoDjango models?

2015-05-13 Thread Thomas Levine
I have multiple GeoDjango models (http://dada.pink/scott2/map/models.py)
and want them to be layers on the same map.

Surely there's a magic way to specify this. What do I do?

-- 
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/20150513193715.GA30126%40d1stkfactory.
For more options, visit https://groups.google.com/d/optout.


Re: How do I display a map with GeoDjango models?

2015-05-14 Thread Thomas Levine
Indeed I can! It looks like I'm going to use Polymaps instead, but the
magic I was looking for was djgeojson.views.TiledGeoJSONLayerView.
I think. It's quite slow, so I might wind up generating them in batch.
Maybe that's why there wasn't such an obvious answer

On 14 May 06:52, Derek wrote:
> Could you not add them as multiple Leaflet layers; each layer pointing to a 
> view for the model in question.  There is a simple overview here:
> 
> http://www.slideshare.net/makinacorpus/team-up-django-and-web-mapping-djangocon-europe-2014
> 
> There is much more detail on the django-leaflet site 
> (e.g. https://github.com/makinacorpus/django-leaflet#default-tiles-layer )
> 
> 
> On Wednesday, 13 May 2015 21:36:13 UTC+2, Thomas Levine wrote:
> >
> > I have multiple GeoDjango models (http://dada.pink/scott2/map/models.py) 
> > and want them to be layers on the same map. 
> >
> > Surely there's a magic way to specify this. What do I do? 
> >

-- 
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/20150514175803.GA11420%40d1stkfactory.
For more options, visit https://groups.google.com/d/optout.