Re: Django Gunicorn Import Error: no module name wsgi

2017-09-03 Thread Melvyn Sopacua
Your Django project really is "weather_station", but you treat
"myproject" as the
project.

Revisit:
https://docs.djangoproject.com/en/1.11/intro/tutorial01/#creating-a-project

And follow instructions to the tee and look at the directory structure.

On Sun, Sep 3, 2017 at 6:04 PM, Jonathan Cheng  wrote:
> I use Python3.5.2 Django1.9
>
> I use `python -m venv venv/weather_station` to create virtual evnironment
> (/home/user/venv)
>
> This is my project tree in Ubuntu /home/user/myproject:
> (`export project=/home/user/myproject`)
>
> myproject
>|
>├── gunicorn.conf.py
>├── static
>│   ├── admin
>└── weather_station
>├── base
>│   ├── migrations
>│   ├── static
>│   └── templates
>└── weather_station
>├── __init__.py
>├── wsgi.py
>├── urls.py
>├── settings
>├── base.py
>├── production.py
> 在此輸入代碼...
>
> __init__.py:
> import pymysql
> pymysql.install_as_MySQLdb()
> wsgi.py
> import os
>
> from django.core.wsgi import get_wsgi_application
>
> os.environ.setdefault("DJANGO_SETTINGS_MODULE",
> "weather_station.settings.production")
>
> application = get_wsgi_application()
> The partial in the settings.base.py:
> BASE_DIR =
> os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__
>
> ROOT_URLCONF = 'weather_station.urls'
>
> WSGI_APPLICATION = 'weather_station.wsgi.application'
>
> STATIC_URL = '/static/'
> In the partial of settings.production.py:
> from .base import *
>
> DEBUG = False
>
> STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'static')
>
> MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'media')
> gunicorn.conf.py:
> import os
>
> bind = '127.0.0.1:8080'
> worders = (os.sysconf('SC_NPROCESSORS_ONLN') * 2) + 1
> loglevel = 'error'
> command = '/home/user/venv/weather_station/bin/gunicorn'
> pythonpath = '/home/user/myproject/weather_station'
>
> And in the /etc/nginx/sites-available/weather.conf:
>
> upstream weather_station {
> server 127.0.0.1:8080;
> }
>
> server {
> listen 80 default_server;
> listen 443 default ssl;
> server_name http://my_ip;
> client_max_body_size 10M;
> keepalive_timeout15;
>
> location /static/ {
> alias   /$project/static/;
> }
> location /media/ {
> alias   /$project/media/;
> }
>
> location / {
> proxy_redirect  off;
> proxy_set_headerHost$host;
> proxy_set_headerX-Real-IP   $remote_addr;
> proxy_set_headerX-Forwarded-For
> $proxy_add_x_forwarded_for;
> proxy_set_headerX-Forwarded-Protocol$scheme;
> proxy_pass  http://myproject;
>
> When I the follwoing command under myproject
> gunicorn -c gunicorn.conf.py weather_station.weather_station.wsgi
>
>
>
> It showed `ImportError: No module named 'weather_station.settings'`
>
> Does any know the reason ?
>
>
> it successfully weather_station.wsgi.
>
> But the new error is  `ImportError: No module named
> 'weather_station.settings'`
>
> detailed log
>
>
>  File "/home/user/myproject/weather_station/weather_station/wsgi.py", line
> 17, in 
> application = get_wsgi_application()
>   File
> "/home/user/.local/lib/python3.5/site-packages/django/core/wsgi.py", line
> 13, in get_wsgi_application
> django.setup()
>   File
> "/home/user/.local/lib/python3.5/site-packages/django/__init__.py", line 17,
> in setup
> configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
>   File
> "/home/user/.local/lib/python3.5/site-packages/django/conf/__init__.py",
> line 55, in __getattr__
> self._setup(name)
>   File
> "/home/user/.local/lib/python3.5/site-packages/django/conf/__init__.py",
> line 43, in _setup
> self._wrapped = Settings(settings_module)
>   File
> "/home/user/.local/lib/python3.5/site-packages/django/conf/__init__.py",
> line 99, in __init__
> mod = importlib.import_module(self.SETTINGS_MODULE)
>   File "/usr/lib/python3.5/importlib/__init__.py", line 126, in
> import_module
> return _bootstrap._gcd_import(name[level:], package, level)
> ImportError: No module named 'weather_station.settings'
>
>
>
>
>
>
>
> --
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/87a81098-2124-4702-a429-4f161cd055d8%40googlegroups.com.
> For more options, visit http

Re: Python 2 versus 3

2017-09-03 Thread Melvyn Sopacua
At this point it makes more sense to upgrade to 3.6, but that
aside, next Django release (2.0) will drop support for Python
2.

Dealing with 2 major version upgrades is not the best platform
for a smooth ride.


On Mon, Sep 4, 2017 at 8:04 AM, BIJAL MANIAR  wrote:
>
> Hi,
>
> I have current django application with django 1.11 and python 2.7.
> Python 2.7 has support till 2020-01-01 and 3.5 has support till 2020-09-13.
> I've been asked to upgrade to Python 3.5. My question is why is there a need
> to upgrade from 2.7 to 3.5 as EOL support for both of them is nearly the
> same.
> Should I invest time in upgrading to Python3.5 or not?
> Which is the latest Python3 LTS version and its EOL support?
>
> Any help would be appreciated.
>
> Thanks,
> Bijal
>
> --
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/df3849b9-1b6a-4a68-b0b4-edbf816d5213%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



-- 
Melvyn Sopacua

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Bgw1GUtjRhZv5fgX7zw-W%2B61K64VBQpwTCvK76uboTTcLNt4Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: from django.utils.six.moves import range, ImportError: cannot import name 'range'

2017-09-03 Thread Raffaele Salmaso
On Sun, Sep 3, 2017 at 4:26 PM, Derek Zeng  wrote:
>
> When I use django==1.10.7, this does not happen.
> When I use django==1.11a1 this happens.
>
Why 1.11a1? Current is 1.11.4

-- 
| Raffaele Salmaso
| https://salmaso.org
| https://bitbucket.org/rsalmaso
| https://github.com/rsalmaso

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CABgH4Js1z0e7yypGD4f7z_eKbMrYWQEMT9viCSCshA1ROhMA_A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Python 2 versus 3

2017-09-03 Thread Lachlan Musicman
Bijal,

Django 2.x - the next release cycle - will be Python 3.x

Most major OSes will be moving to Python 3.x in their next release (eg in
RedHat/CentOS 7.4 (I think))...

If it's no big deal - and it really shouldn't be - you should move to
Python 3.x



Cheers
L.

--
"The antidote to apocalypticism is *apocalyptic civics*. Apocalyptic civics
is the insistence that we cannot ignore the truth, nor should we panic
about it. It is a shared consciousness that our institutions have failed
and our ecosystem is collapsing, yet we are still here — and we are
creative agents who can shape our destinies. Apocalyptic civics is the
conviction that the only way out is through, and the only way through is
together. "

*Greg Bloom* @greggish
https://twitter.com/greggish/status/873177525903609857

On 4 September 2017 at 16:04, BIJAL MANIAR  wrote:

>
> Hi,
>
> I have current django application with django 1.11 and python 2.7.
> Python 2.7 has support till 2020-01-01 and 3.5 has support till 2020-09-13.
> I've been asked to upgrade to Python 3.5. My question is why is there a
> need to upgrade from 2.7 to 3.5 as EOL support for both of them is nearly
> the same.
> Should I invest time in upgrading to Python3.5 or not?
> Which is the latest Python3 LTS version and its EOL support?
>
> Any help would be appreciated.
>
> Thanks,
> Bijal
>
> --
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/df3849b9-1b6a-4a68-b0b4-edbf816d5213%40googlegroups.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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGBeqiN9KPm3MEmG3boqM0nRHu4fL%3DeCP-ESOGPdYq9XKMN%3Dhg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Python 2 versus 3

2017-09-03 Thread Antonis Christofides
Hi,

the reason is that Python 3.6 is backwards-compatible with 3.5. Same thing with
3.7 and 3.8 and generally 3.x for x>=6. In contrast, Python 3.0 is
backwards-incompatible with 2.7. So if you upgrade to 3.5 now, your program will
also run in any Python 3 version later than 3.5. The big thing is to upgrade
from Python 2 to Python 3, the minor version numbers don't play any significant
role. So yes, you should definitely invest in upgrading to Python 3.

As far as I know Python doesn't distinguish between LTS and non-LTS versions.
The latest version is 3.6. There's a convenient version table at
https://en.wikipedia.org/wiki/CPython#Version_history.

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com

On 2017-09-04 09:04, BIJAL MANIAR wrote:
>
> Hi,
>
> I have current django application with django 1.11 and python 2.7.
> Python 2.7 has support till 2020-01-01 and 3.5 has support till 2020-09-13.
> I've been asked to upgrade to Python 3.5. My question is why is there a need
> to upgrade from 2.7 to 3.5 as EOL support for both of them is nearly the 
> same. 
> Should I invest time in upgrading to Python3.5 or not?
> Which is the latest Python3 LTS version and its EOL support?
>
> Any help would be appreciated.
>
> Thanks,
> Bijal
> -- 
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/df3849b9-1b6a-4a68-b0b4-edbf816d5213%40googlegroups.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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/47fd8458-6ed0-1554-b3ee-3c11d857a570%40djangodeployment.com.
For more options, visit https://groups.google.com/d/optout.


Re: from django.utils.six.moves import range, ImportError: cannot import name 'range'

2017-09-03 Thread Melvyn Sopacua
Could you turn off DEBUG and check what the problem is then?
The reason is that I want to make sure we're not judging the side
effect of *rendering* the exception.

On Sun, Sep 3, 2017 at 11:52 PM, Derek Zeng  wrote:
> it's the same in either versions of python. the output was captured when i
> was just debugging it in 3.5.
>
> On Sun, Sep 3, 2017 at 2:55 PM, James Schneider 
> wrote:
>>
>>
>>
>>   File
>> "/Users/coderek/Documents/projects/py3.5/lib/python3.5/site-packages/django/contrib/staticfiles/storage.py",
>> line 21, in 
>> from django.utils.six.moves import range
>> ImportError: cannot import name 'range'
>>
>>
>> Are you sure you're using 3.6.2? Do you have another virtualenv with 3.5
>> and no Django installed?
>>
>> -James
>>
>> --
>> 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/49blpAjNxYc/unsubscribe.
>> To unsubscribe from this group and all its topics, 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 https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CA%2Be%2BciV4vpt7Vk%3D8GDS_wNQHqhsuwA5vcfakWo%3DoVjQziXLdxA%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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAAzyz%2BG0MTUNd8xm8ajNby38eoi7Xmj6RgXBZwp2WfAS-n9s2g%40mail.gmail.com.
>
> For more options, visit https://groups.google.com/d/optout.



-- 
Melvyn Sopacua

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Bgw1GWxFhcKwAe%2B-cwJq9A6N0m-tcyS7N4%3D%3D0Uai1RrG%2Be%3Dpg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Python 2 versus 3

2017-09-03 Thread BIJAL MANIAR

Hi,

I have current django application with django 1.11 and python 2.7.
Python 2.7 has support till 2020-01-01 and 3.5 has support till 2020-09-13.
I've been asked to upgrade to Python 3.5. My question is why is there a 
need to upgrade from 2.7 to 3.5 as EOL support for both of them is nearly 
the same. 
Should I invest time in upgrading to Python3.5 or not?
Which is the latest Python3 LTS version and its EOL support?

Any help would be appreciated.

Thanks,
Bijal

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/df3849b9-1b6a-4a68-b0b4-edbf816d5213%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Weird date math bug?

2017-09-03 Thread Lachlan Musicman
On 1 September 2017 at 16:13, Melvyn Sopacua  wrote:

> A few tips on your code:
>
> def get_latest_chemo(self):
> chemo = ChemoRegime.objects.filter(pat
> ient=self).latest('stop_date')
>
> class ChemoRegime(models.Model):
> patient = models.ForeignKey(Patient, on_delete=models.CASCADE)
>
> Use the related manager here. To make it readable, use:
>
> class ChemoRegime(models.Model):
> patient = models.ForeignKey(Patient, on_delete=models.CASCADE,
> related_name='chemo_regimes')
>
> class Patient(models.Model):
> def get_latest_chemo(self):
> return self.chemo_regimes.latest('stop_date')
>
> When providing properties for use in templates, make them properties -
> makes the template more readable:
>
> @property
> def latest_chemo(self):
>  return self.chemo_regimes.latest('stop_date')
>
> {{ patient.latest_chemo }}
>
> Similarly you can abstract active regimes:
>
> class ChemoRegime(models.Model):
>  @property
>  def is_active(self):
>   return self.stop_date is None
>
> {% if chemo.is_active %}Current{% endif %}
>
>
> Of course, latest_chemo, should really be this if
> active and non-active regimes can be mixed:
>
> @property
> def has_active_chemo(self):
>  return self.chemo_regimes.filter(stop_date__isnull=True).count()
> > 0
>
> @property
> def latest_chemo(self):
>  if not self.chemo_regimes.count():
>   return None
>  if self.has_active_chemo:
>   return self.chemo_regimes.latest('start_date')
>  return self.chemo_regimes.latest('stop_date')
>
> Hope this helps :)
>


Melvyn - have only just got around to implementing your suggestions.
Excellent, worked a treat. Thank you for the new tricks!

Cheers
L.







--
"The antidote to apocalypticism is *apocalyptic civics*. Apocalyptic civics
is the insistence that we cannot ignore the truth, nor should we panic
about it. It is a shared consciousness that our institutions have failed
and our ecosystem is collapsing, yet we are still here — and we are
creative agents who can shape our destinies. Apocalyptic civics is the
conviction that the only way out is through, and the only way through is
together. "

*Greg Bloom* @greggish https://twitter.com/greggish/
status/873177525903609857

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGBeqiOt%3DQGLWfxYxeYW2ajogpoSoZQLib3r727Bvsx3FB6AEg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: from django.utils.six.moves import range, ImportError: cannot import name 'range'

2017-09-03 Thread Derek Zeng
it's the same in either versions of python. the output was captured when i
was just debugging it in 3.5.

On Sun, Sep 3, 2017 at 2:55 PM, James Schneider 
wrote:

>
>
>   File 
> "/Users/coderek/Documents/projects/py3.5/lib/python3.5/site-packages/django/contrib/staticfiles/storage.py",
>  line 21, in 
> from django.utils.six.moves import range
> ImportError: cannot import name 'range'
>
>
> Are you sure you're using 3.6.2? Do you have another virtualenv with 3.5
> and no Django installed?
>
> -James
>
> --
> 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/49blpAjNxYc/unsubscribe.
> To unsubscribe from this group and all its topics, 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CA%2Be%2BciV4vpt7Vk%3D8GDS_wNQHqhsuwA5vcfakWo%
> 3DoVjQziXLdxA%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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAAzyz%2BG0MTUNd8xm8ajNby38eoi7Xmj6RgXBZwp2WfAS-n9s2g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: from django.utils.six.moves import range, ImportError: cannot import name 'range'

2017-09-03 Thread James Schneider
  File 
"/Users/coderek/Documents/projects/py3.5/lib/python3.5/site-packages/django/contrib/staticfiles/storage.py",
line 21, in 
from django.utils.six.moves import range
ImportError: cannot import name 'range'


Are you sure you're using 3.6.2? Do you have another virtualenv with 3.5
and no Django installed?

-James

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciV4vpt7Vk%3D8GDS_wNQHqhsuwA5vcfakWo%3DoVjQziXLdxA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Gunicorn Import Error: no module name wsgi

2017-09-03 Thread M Hashmi
Try:

gunicorn --bind ip:port wsgi:application

Make sure you run it from the directory where manage.py is located.
Regards,
M

On Sun, Sep 3, 2017 at 9:04 AM, Jonathan Cheng 
wrote:

> I use Python3.5.2 Django1.9
>
> I use `python -m venv venv/weather_station` to create virtual evnironment
> (/home/user/venv)
>
> This is my project tree in Ubuntu /home/user/myproject:
> (`export project=/home/user/myproject`)
>
> myproject
>|
>├── gunicorn.conf.py
>├── static
>│   ├── admin
>└── weather_station
>├── base
>│   ├── migrations
>│   ├── static
>│   └── templates
>└── weather_station
>├── __init__.py
>├── wsgi.py
>├── urls.py
>├── settings
>├── base.py
>├── production.py
> 在此輸入代碼...
>
> __init__.py:
> import pymysql
> pymysql.install_as_MySQLdb()
> wsgi.py
> import os
>
> from django.core.wsgi import get_wsgi_application
>
> os.environ.setdefault("DJANGO_SETTINGS_MODULE",
> "weather_station.settings.production")
>
> application = get_wsgi_application()
> The partial in the settings.base.py:
> BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.
> path.abspath(__file__
>
> ROOT_URLCONF = 'weather_station.urls'
>
> WSGI_APPLICATION = 'weather_station.wsgi.application'
>
> STATIC_URL = '/static/'
> In the partial of settings.production.py:
> from .base import *
>
> DEBUG = False
>
> STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'static')
>
> MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'media')
> gunicorn.conf.py:
> import os
>
> bind = '127.0.0.1:8080'
> worders = (os.sysconf('SC_NPROCESSORS_ONLN') * 2) + 1
> loglevel = 'error'
> command = '/home/user/venv/weather_station/bin/gunicorn'
> pythonpath = '/home/user/myproject/weather_station'
>
> And in the /etc/nginx/sites-available/weather.conf:
>
> upstream weather_station {
> server 127.0.0.1:8080;
> }
>
> server {
> listen 80 default_server;
> listen 443 default ssl;
> server_name http://my_ip;
> client_max_body_size 10M;
> keepalive_timeout15;
>
> location /static/ {
> alias   /$project/static/;
> }
> location /media/ {
> alias   /$project/media/;
> }
>
> location / {
> proxy_redirect  off;
> proxy_set_headerHost$host;
> proxy_set_headerX-Real-IP   $remote_addr;
> proxy_set_headerX-Forwarded-For
> $proxy_add_x_forwarded_for;
> proxy_set_headerX-Forwarded-Protocol$scheme;
> proxy_pass  http://myproject;
>
> When I the follwoing command under myproject
> gunicorn -c gunicorn.conf.py weather_station.weather_station.wsgi
>
>
>
> It showed `ImportError: No module named 'weather_station.settings'`
>
> Does any know the reason ?
>
>
> it successfully weather_station.wsgi.
>
> But the new error is  `ImportError: No module named
> 'weather_station.settings'`
>
> detailed log
>
>
>  File "/home/user/myproject/weather_station/weather_station/wsgi.py",
> line 17, in 
> application = get_wsgi_application()
>   File "/home/user/.local/lib/python3.5/site-packages/
> django/core/wsgi.py", line 13, in get_wsgi_application
> django.setup()
>   File "/home/user/.local/lib/python3.5/site-packages/
> django/__init__.py", line 17, in setup
> configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
>   File "/home/user/.local/lib/python3.5/site-packages/
> django/conf/__init__.py", line 55, in __getattr__
> self._setup(name)
>   File "/home/user/.local/lib/python3.5/site-packages/
> django/conf/__init__.py", line 43, in _setup
> self._wrapped = Settings(settings_module)
>   File "/home/user/.local/lib/python3.5/site-packages/
> django/conf/__init__.py", line 99, in __init__
> mod = importlib.import_module(self.SETTINGS_MODULE)
>   File "/usr/lib/python3.5/importlib/__init__.py", line 126, in
> import_module
> return _bootstrap._gcd_import(name[level:], package, level)
> ImportError: No module named 'weather_station.settings'
>
>
>
>
>
>
>
> --
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/87a81098-2124-4702-a429-4f161cd055d8%40googlegroups.com
> 
> .
> For more

Django Gunicorn Import Error: no module name wsgi

2017-09-03 Thread Jonathan Cheng
I use Python3.5.2 Django1.9

I use `python -m venv venv/weather_station` to create virtual evnironment 
(/home/user/venv)

This is my project tree in Ubuntu /home/user/myproject:
(`export project=/home/user/myproject`)

myproject
   |
   ├── gunicorn.conf.py
   ├── static
   │   ├── admin
   └── weather_station
   ├── base
   │   ├── migrations
   │   ├── static
   │   └── templates
   └── weather_station
   ├── __init__.py
   ├── wsgi.py
   ├── urls.py
   ├── settings
   ├── base.py
   ├── production.py
在此輸入代碼...

__init__.py:
import pymysql
pymysql.install_as_MySQLdb()
wsgi.py
import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", 
"weather_station.settings.production")

application = get_wsgi_application()
The partial in the settings.base.py:
BASE_DIR = 
os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__
 
ROOT_URLCONF = 'weather_station.urls'

WSGI_APPLICATION = 'weather_station.wsgi.application'

STATIC_URL = '/static/'
In the partial of settings.production.py:
from .base import *   

DEBUG = False

STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'static')

MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'media')
gunicorn.conf.py:
import os
 
bind = '127.0.0.1:8080'
worders = (os.sysconf('SC_NPROCESSORS_ONLN') * 2) + 1
loglevel = 'error'
command = '/home/user/venv/weather_station/bin/gunicorn'
pythonpath = '/home/user/myproject/weather_station'

And in the /etc/nginx/sites-available/weather.conf:

upstream weather_station {
server 127.0.0.1:8080;
}

server {
listen 80 default_server;
listen 443 default ssl;
server_name http://my_ip;
client_max_body_size 10M;
keepalive_timeout15;

location /static/ {
alias   /$project/static/;
}
location /media/ {
alias   /$project/media/;
}

location / {
proxy_redirect  off;
proxy_set_headerHost$host;
proxy_set_headerX-Real-IP   $remote_addr;
proxy_set_headerX-Forwarded-For 
$proxy_add_x_forwarded_for;
proxy_set_headerX-Forwarded-Protocol$scheme;
proxy_pass  http://myproject;

When I the follwoing command under myproject
gunicorn -c gunicorn.conf.py weather_station.weather_station.wsgi



It showed `ImportError: No module named 'weather_station.settings'`

Does any know the reason ?


it successfully weather_station.wsgi.

But the new error is  `ImportError: No module named 
'weather_station.settings'`

detailed log

   
 File "/home/user/myproject/weather_station/weather_station/wsgi.py", line 
17, in 
application = get_wsgi_application()
  File 
"/home/user/.local/lib/python3.5/site-packages/django/core/wsgi.py", line 13
, in get_wsgi_application
django.setup()
  File 
"/home/user/.local/lib/python3.5/site-packages/django/__init__.py", line 17, 
in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
  File 
"/home/user/.local/lib/python3.5/site-packages/django/conf/__init__.py", 
line 55, in __getattr__
self._setup(name)
  File 
"/home/user/.local/lib/python3.5/site-packages/django/conf/__init__.py", 
line 43, in _setup
self._wrapped = Settings(settings_module)
  File 
"/home/user/.local/lib/python3.5/site-packages/django/conf/__init__.py", 
line 99, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in 
import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: No module named 'weather_station.settings'







-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/87a81098-2124-4702-a429-4f161cd055d8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: from django.utils.six.moves import range, ImportError: cannot import name 'range'

2017-09-03 Thread Derek Zeng
It is a project I developed in ubuntu and currently running on a ubuntu 
server. I just bought a new mac mini, so I would like to develop on mac.

I have isolated the problem to the django version.
 
When I use django==1.10.7, this does not happen.
When I use django==1.11a1 this happens. 

This is the full stack trace:

Traceback (most recent call last):
  File 
"/Users/coderek/Documents/projects/py3.5/lib/python3.5/site-packages/django/contrib/staticfiles/handlers.py",
 line 63, in __call__
return self.application(environ, start_response)
  File 
"/Users/coderek/Documents/projects/py3.5/lib/python3.5/site-packages/django/core/handlers/wsgi.py",
 line 157, in __call__
response = self.get_response(request)
  File 
"/Users/coderek/Documents/projects/py3.5/lib/python3.5/site-packages/django/core/handlers/base.py",
 line 124, in get_response
response = self._middleware_chain(request)
  File 
"/Users/coderek/Documents/projects/py3.5/lib/python3.5/site-packages/django/core/handlers/exception.py",
 line 43, in inner
response = response_for_exception(request, exc)
  File 
"/Users/coderek/Documents/projects/py3.5/lib/python3.5/site-packages/django/core/handlers/exception.py",
 line 93, in response_for_exception
response = handle_uncaught_exception(request, get_resolver(get_urlconf()), 
sys.exc_info())
  File 
"/Users/coderek/Documents/projects/py3.5/lib/python3.5/site-packages/django/core/handlers/exception.py",
 line 139, in handle_uncaught_exception
return debug.technical_500_response(request, *exc_info)
  File 
"/Users/coderek/Documents/projects/py3.5/lib/python3.5/site-packages/django_extensions/management/technical_response.py",
 line 6, in null_technical_500_response
six.reraise(exc_type, exc_value, tb)
  File 
"/Users/coderek/Documents/projects/py3.5/lib/python3.5/site-packages/six.py", 
line 686, in reraise
raise value
  File 
"/Users/coderek/Documents/projects/py3.5/lib/python3.5/site-packages/django/core/handlers/exception.py",
 line 41, in inner
response = get_response(request)
  File 
"/Users/coderek/Documents/projects/py3.5/lib/python3.5/site-packages/django/core/handlers/base.py",
 line 249, in _legacy_get_response
response = self._get_response(request)
  File 
"/Users/coderek/Documents/projects/py3.5/lib/python3.5/site-packages/django/core/handlers/base.py",
 line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
  File 
"/Users/coderek/Documents/projects/py3.5/lib/python3.5/site-packages/django/core/handlers/base.py",
 line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/coderek/Documents/projects/mysite/mysite/urls.py", line 78, in 
home
return render(req, 'index.html', {'posts': posts})
  File 
"/Users/coderek/Documents/projects/py3.5/lib/python3.5/site-packages/django/shortcuts.py",
 line 30, in render
content = loader.render_to_string(template_name, context, request, 
using=using)
  File 
"/Users/coderek/Documents/projects/py3.5/lib/python3.5/site-packages/django/template/loader.py",
 line 68, in render_to_string
return template.render(context, request)
  File 
"/Users/coderek/Documents/projects/py3.5/lib/python3.5/site-packages/django/template/backends/django.py",
 line 66, in render
return self.template.render(context)
  File 
"/Users/coderek/Documents/projects/py3.5/lib/python3.5/site-packages/django/template/base.py",
 line 207, in render
return self._render(context)
  File 
"/Users/coderek/Documents/projects/py3.5/lib/python3.5/site-packages/django/template/base.py",
 line 199, in _render
return self.nodelist.render(context)
  File 
"/Users/coderek/Documents/projects/py3.5/lib/python3.5/site-packages/django/template/base.py",
 line 990, in render
bit = node.render_annotated(context)
  File 
"/Users/coderek/Documents/projects/py3.5/lib/python3.5/site-packages/django/template/base.py",
 line 957, in render_annotated
return self.render(context)
  File 
"/Users/coderek/Documents/projects/py3.5/lib/python3.5/site-packages/django/template/loader_tags.py",
 line 177, in render
return compiled_parent._render(context)
  File 
"/Users/coderek/Documents/projects/py3.5/lib/python3.5/site-packages/django/template/base.py",
 line 199, in _render
return self.nodelist.render(context)
  File 
"/Users/coderek/Documents/projects/py3.5/lib/python3.5/site-packages/django/template/base.py",
 line 990, in render
bit = node.render_annotated(context)
  File 
"/Users/coderek/Documents/projects/py3.5/lib/python3.5/site-packages/django/template/base.py",
 line 957, in render_annotated
return self.render(context)
  File 
"/Users/coderek/Documents/projects/py3.5/lib/python3.5/site-packages/compressor/templatetags/compress.py",
 line 131, in render
return self.render_compressed(context, self.kind, self.mode, forced=forced)
  File 
"/Users/coderek/Documents/projects/py3.5/lib/python3.5/site-packages/compressor/templatetags/compress.

Re: Testing file upload via a form?

2017-09-03 Thread Melvyn Sopacua
It certainly isn't trivial.

First and foremost, write fat models and Managers, but lean views.

Rather then putting complex queries in views, I have a strong bias
to writing manager methods (or QuerySet methods, if I feel it's
reusable in more then one Manager - see Manager.from_queryset [1]).

Further more, I tend to use the setup described here [2] also for
projects. But for the `test_settings.py` I use:

from project_app.settings import *

INSTALLED_APPS += ['tests.apps.TestsConfig']

This makes it trivial to test fields on their own, by creating models
that only exist in the test environment.

Normally, you want to test all components on their own, but with
forms being so tightly coupled to and influenced by views and urls,
it is non-trivial to predict what affects your form and thus test for it.
It's easy to get 100% coverage on your form and still know nothing,
because the input variations are important.
Yes, it's possible to do with different initialization, but you're going
to test your views anyway, so why not use the test client, as your
views eventually determine what happens with them and are pretty
much the only way to use them. On top of that, you're testing your
urls for free.

So in general, a Django test suite consists of:
* model tests
* view tests using django.test.Client
* template tests [3]
* command tests [4]
* utility tests

Hope this helps,

[1] 
https://docs.djangoproject.com/en/1.11/topics/db/managers/#creating-a-manager-with-queryset-methods
[2] 
https://docs.djangoproject.com/en/1.11/topics/testing/advanced/#testing-reusable-applications
[3] shameless plug warning:
http://django-xtc.readthedocs.io/en/latest/index.html
[4] 
https://docs.djangoproject.com/en/1.11/ref/django-admin/#django.core.management.call_command

On Sun, Sep 3, 2017 at 10:05 AM, Derek  wrote:
> I have been looking for a decent guide that covers testing in a solid,
> thorough way - there are lots of fragmented pieces that cover
> bits-and-pieces of what is needed for tests but not all the cases with a
> start-to-end comprehensive approach for everything ("Obey the Testing Goat"
> comes closest). I need to cover cases for the admin as well - with actions
> and intermediate forms, some with file uploads. In those case, I assume (?)
> that the action logic is equivalent to a view.
>
> The Django docs show examples as well but I have not see where they cover
> everything.
>
> This may all seem like trivial knowledge to people who have already done all
> this, but I struggle to see the full picture of what a whole test suite
> should look like, and what the details of all the tests would be.
>
>
> On 3 September 2017 at 09:07, James Schneider 
> wrote:
>>
>>
>>
>> On Sep 1, 2017 3:00 PM, "Derek"  wrote:
>>
>> Thanks Melvyn
>>
>> I already have tests for the processing of data when it has been uploaded
>> - which is actually the critical issue for the application.  The "view" is
>> just really a thin wrapper around the two steps : form display & upload and
>> then the file processing itself : and those are the parts I need tests for.
>>
>>
>> I'd have to agree with Melvin. You should be testing your view code as
>> well, which would incorporate the tests for the form class. If the view is
>> broken out interacts badly with the form for whatever reason, the fact that
>> the form works on it's own is irrelevant. Plus it isn't that hard to add in.
>>
>> I would test the view even if it is boiler plate code shared by all of
>> your forms, because you need to be certain that the combination of the view
>> and form in question work together.
>>
>> -James
>>
>> --
>> 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/GUStj-3rzD8/unsubscribe.
>> To unsubscribe from this group and all its topics, 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 https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CA%2Be%2BciUgbWkGFVrqBWKAYdifP%2BjTchZwHR0-GfPKGcTjP%3DBjfA%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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAF1Wu3MqT1V85StnBg8D_eqrcjH%2BebjvDW41xg_V1t%3D9%3DeUk-Q%40mail.gmail.com.
>
> For more options, visit https://groups.google.com/d/optout.



-- 
Melvyn Sopacua

-- 
You received this

Re: Testing file upload via a form?

2017-09-03 Thread Derek
I have been looking for a decent guide that covers testing in a solid,
thorough way - there are lots of fragmented pieces that cover
bits-and-pieces of what is needed for tests but not all the cases with a
start-to-end comprehensive approach for everything ("Obey the Testing Goat"
comes closest). I need to cover cases for the admin as well - with actions
and intermediate forms, some with file uploads. In those case, I assume (?)
that the action logic is equivalent to a view.

The Django docs show examples as well but I have not see where they cover
everything.

This may all seem like trivial knowledge to people who have already done
all this, but I struggle to see the full picture of what a whole test suite
should look like, and what the details of all the tests would be.


On 3 September 2017 at 09:07, James Schneider 
wrote:

>
>
> On Sep 1, 2017 3:00 PM, "Derek"  wrote:
>
> Thanks Melvyn
>
> I already have tests for the processing of data when it has been uploaded
> - which is actually the critical issue for the application.  The "view" is
> just really a thin wrapper around the two steps : form display & upload and
> then the file processing itself : and those are the parts I need tests for.
>
>
> I'd have to agree with Melvin. You should be testing your view code as
> well, which would incorporate the tests for the form class. If the view is
> broken out interacts badly with the form for whatever reason, the fact that
> the form works on it's own is irrelevant. Plus it isn't that hard to add
> in.
>
> I would test the view even if it is boiler plate code shared by all of
> your forms, because you need to be certain that the combination of the view
> and form in question work together.
>
> -James
>
> --
> 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/GUStj-3rzD8/unsubscribe.
> To unsubscribe from this group and all its topics, 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CA%2Be%2BciUgbWkGFVrqBWKAYdifP%
> 2BjTchZwHR0-GfPKGcTjP%3DBjfA%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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAF1Wu3MqT1V85StnBg8D_eqrcjH%2BebjvDW41xg_V1t%3D9%3DeUk-Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Testing file upload via a form?

2017-09-03 Thread James Schneider
On Sep 1, 2017 3:00 PM, "Derek"  wrote:

Thanks Melvyn

I already have tests for the processing of data when it has been uploaded -
which is actually the critical issue for the application.  The "view" is
just really a thin wrapper around the two steps : form display & upload and
then the file processing itself : and those are the parts I need tests for.


I'd have to agree with Melvin. You should be testing your view code as
well, which would incorporate the tests for the form class. If the view is
broken out interacts badly with the form for whatever reason, the fact that
the form works on it's own is irrelevant. Plus it isn't that hard to add
in.

I would test the view even if it is boiler plate code shared by all of your
forms, because you need to be certain that the combination of the view and
form in question work together.

-James

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciUgbWkGFVrqBWKAYdifP%2BjTchZwHR0-GfPKGcTjP%3DBjfA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.