Re: best practices for location of start up code

2017-09-23 Thread Antonis Christofides
Hello Larry,

The Django development server runs in more than one thread, which is probably
why your initialization code run twice.

OTOH, it run only once on production probably because you have configured uwsgi
to run only one process (it's possible that this is the default on single-core
machines). However, we usually want to run at least two processes.

Running initialization code only once per wsgi server (re)start instead of once
per process start seems a bit strange. Why do you need this?

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com

On 2017-09-23 21:50, Larry Martell wrote:
> On Sat, Sep 23, 2017 at 2:39 PM, Larry Martell  
> wrote:
>> On Sat, Sep 23, 2017 at 1:34 PM, James Schneider
>>  wrote:
>>>
>>> On Sep 22, 2017 2:58 PM, "Larry Martell"  wrote:
>>>
>>> We have some code we want to run 1 time when our django app is
>>> started. What is the best place for this? I tried putting it in my
>>> app's config function, but from there I get:
>>>
>>> *** AppRegistryNotReady: Apps aren't loaded yet.
>>>
>>>
>>> Once as in only when the app is initially deployed, or once every time the
>>> web server process is started?
>>>
>>> Note that if you place code to run every time the web process is started,
>>> that it will run for every process, and most web servers spawn multiple
>>> processes.
>> I'm looking to run it once when the web server is started (not each
>> time another process of the web server is started)
> I am using nginx and uwsgi. I tried experimenting with Antonis
> Christofides suggestion of using AppConfig.ready(). That seems to get
> called just once when I start (or restart uwsgi). I tried many
> connections to the server from different browsers and computers, but
> still that was only called once. Is that something I can count on?
>
> Note, when running the devel django server it was called twice at
> start up, but when the 'real' server it was only called once. Anyone
> know why I got the 2 calls here?
>

-- 
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/1744bd17-68f4-34d7-13c1-c15813b6d15a%40djangodeployment.com.
For more options, visit https://groups.google.com/d/optout.


Re: capturing url pattern from html forms

2017-09-23 Thread James Schneider
On Sep 23, 2017 1:27 PM, "Mel DeJesus"  wrote:

Unfortunately, I didn't show my entire URLpatterns list, and the ^item/$
 seems to interfere with the ^$ of the previous:  Any suggestions for a
work around? thanks again.

from django.conf.urls import include, url
from django.contrib import admin
from rest_framework.urlpatterns import format_suffix_patterns
from durham_app import views

urlpatterns = [
# Examples:
url(r'^admin/', include(admin.site.urls)),

url(r'^$', views.index, name='index'),
url(r'^item/$', views.item_detail, name='item_detail'),
url(r'^items/', views.ItemList.as_view()),
]

urlpatterns = format_suffix_patterns(urlpatterns)



There isn't really a reason that any of those URL patterns would interfere
with each other. I'd change the last one to r'items/$', but otherwise they
look fine.

What do you mean by 'interfere'?

-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%2BciU_e0k8eLpt%2BjJvRGFPsg%2B_Gota6F5Z0omrm9-xhg1dgQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: capturing url pattern from html forms

2017-09-23 Thread Mel DeJesus
Unfortunately, I didn't show my entire URLpatterns list, and the ^item/$ 
 seems to interfere with the ^$ of the previous:  Any suggestions for a 
work around? thanks again. 

from django.conf.urls import include, url
from django.contrib import admin
from rest_framework.urlpatterns import format_suffix_patterns
from durham_app import views

urlpatterns = [
# Examples:
url(r'^admin/', include(admin.site.urls)),

url(r'^$', views.index, name='index'),
url(r'^item/$', views.item_detail, name='item_detail'),
url(r'^items/', views.ItemList.as_view()),
]

urlpatterns = format_suffix_patterns(urlpatterns)





On Saturday, September 23, 2017 at 3:41:16 PM UTC-4, Daniel Roseman wrote:
>
>
>
> On Saturday, 23 September 2017 19:48:37 UTC+1, Mel DeJesus wrote:
>>
>>
>> Hi - 
>>
>> If the number '1' is submitted with the form below, the following url is 
>> created:  http://localhost:8000/item/?id=1
>>
>> But I continually get a page not found.  How can I style the regex in the 
>> urlpatterns so that this url registers?  Thanks. 
>>
>> 
>> Item Name:
>> 
>> 
>> 
>> 
>>
>> I'm attempting to capture here: 
>>
>> urlpatterns = [
>> # Examples:
>> url(r'^admin/', include(admin.site.urls)),
>> # url(r'^item\/\?id=(?P\d+)/', views.item_detail, name='item_detail'),
>> url(r'^item/(?P\d+)/', views.item_detail, name='item_detail'),
>> # JSON files 
>>
>>
>>
>
> GET parameters are not captured in URL patterns. Just accept `^item/$` and 
> get the data inside the view via `request.GET['id']`.
> -- 
> DR. 
>

-- 
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/f4f72339-6051-4c8e-89e7-f2ac28d1ec77%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: capturing url pattern from html forms

2017-09-23 Thread Mel DeJesus
Awesome, thanks!

Following your suggestion, I went to views and I assigned the 
request.GET['id'] to a variable and was able to use it! 



On Saturday, September 23, 2017 at 3:41:16 PM UTC-4, Daniel Roseman wrote:
>
>
>
> On Saturday, 23 September 2017 19:48:37 UTC+1, Mel DeJesus wrote:
>>
>>
>> Hi - 
>>
>> If the number '1' is submitted with the form below, the following url is 
>> created:  http://localhost:8000/item/?id=1
>>
>> But I continually get a page not found.  How can I style the regex in the 
>> urlpatterns so that this url registers?  Thanks. 
>>
>> 
>> Item Name:
>> 
>> 
>> 
>> 
>>
>> I'm attempting to capture here: 
>>
>> urlpatterns = [
>> # Examples:
>> url(r'^admin/', include(admin.site.urls)),
>> # url(r'^item\/\?id=(?P\d+)/', views.item_detail, name='item_detail'),
>> url(r'^item/(?P\d+)/', views.item_detail, name='item_detail'),
>> # JSON files 
>>
>>
>>
>
> GET parameters are not captured in URL patterns. Just accept `^item/$` and 
> get the data inside the view via `request.GET['id']`.
> -- 
> DR. 
>

-- 
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/f368a66e-0602-4dba-aad7-f832b22a4b32%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: First steps in Django 1.11.5 and I have my first error

2017-09-23 Thread Gerardo Palazuelos Guerrero
Hi,
Another beginner here .

 I'm not sure what you did exactly so it caused your error.

But I'm following the django girls tutorial; I cannot completely express how 
good it was for me, it was my first tutorial.

I want to recommend you to check it out, it will guide you on how to run the 
app for the first time.

Regards,
Gerardo.

---
Gerardo Palazuelos
Enviado desde mi iPhone


> El 23/09/2017, a las 09:01, Diego Muiño Orallo  escribió:
> 
> Hello, this is my first app in Django and I have the next error:
> When I launch python manage.py runserver --settings=eventus.settings.local 
> apear this error:
> 
> Unhandled exception in thread started by  check_errors..wrapper at 0x110c72158>
> 
> Traceback (most recent call last):
> 
>   File 
> "/Users/dmuino/eventus/lib/python3.6/site-packages/django/utils/autoreload.py",
>  line 228, in wrapper
> 
> fn(*args, **kwargs)
> 
>   File 
> "/Users/dmuino/eventus/lib/python3.6/site-packages/django/core/management/commands/runserver.py",
>  line 117, in inner_run
> 
> autoreload.raise_last_exception()
> 
>   File 
> "/Users/dmuino/eventus/lib/python3.6/site-packages/django/utils/autoreload.py",
>  line 251, in raise_last_exception
> 
> six.reraise(*_exception)
> 
>   File 
> "/Users/dmuino/eventus/lib/python3.6/site-packages/django/utils/six.py", line 
> 685, in reraise
> 
> raise value.with_traceback(tb)
> 
>   File 
> "/Users/dmuino/eventus/lib/python3.6/site-packages/django/utils/autoreload.py",
>  line 228, in wrapper
> 
> fn(*args, **kwargs)
> 
>   File 
> "/Users/dmuino/eventus/lib/python3.6/site-packages/django/__init__.py", line 
> 27, in setup
> 
> apps.populate(settings.INSTALLED_APPS)
> 
>   File 
> "/Users/dmuino/eventus/lib/python3.6/site-packages/django/apps/registry.py", 
> line 85, in populate
> 
> app_config = AppConfig.create(entry)
> 
>   File 
> "/Users/dmuino/eventus/lib/python3.6/site-packages/django/apps/config.py", 
> line 120, in create
> 
> mod = import_module(mod_path)
> 
>   File "/Users/dmuino/eventus/lib/python3.6/importlib/__init__.py", line 126, 
> in import_module
> 
> return _bootstrap._gcd_import(name[level:], package, level)
> 
>   File "", line 978, in _gcd_import
> 
>   File "", line 961, in _find_and_load
> 
>   File "", line 948, in _find_and_load_unlocked
> 
> ModuleNotFoundError: No module named 'myapps'
> 
> 
> I separated my setting for different archives.
> My setting/base.py is:
> """
> Django settings for eventus project.
> 
> Generated by 'django-admin startproject' using Django 1.11.5.
> 
> For more information on this file, see
> https://docs.djangoproject.com/en/1.11/topics/settings/
> 
> For the full list of settings and their values, see
> https://docs.djangoproject.com/en/1.11/ref/settings/
> """
> 
> import os
> 
> # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
> BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
> 
> 
> # Quick-start development settings - unsuitable for production
> # See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
> 
> # SECURITY WARNING: keep the secret key used in production secret!
> SECRET_KEY = 'vmtu6=u+a-c_qle*+m(kwjpr$n^0ecb&5r0!#=l0vmvw_4j3tn'
> 
> # SECURITY WARNING: don't run with debug turned on in production!
> DEBUG = True
> 
> ALLOWED_HOSTS = []
> 
> 
> # Application definition
> 
> DJANGO_APPS = [
> 'django.contrib.admin',
> 'django.contrib.auth',
> 'django.contrib.contenttypes',
> 'django.contrib.sessions',
> 'django.contrib.messages',
> 'django.contrib.staticfiles',
> ]
> 
> LOCAL_APPS = [
> 'myapps.events',
> ]
> 
> THIRD_PARTY_APPS = [
> ]
> 
> INSTALLED_APPS = DJANGO_APPS + LOCAL_APPS + THIRD_PARTY_APPS
> 
> MIDDLEWARE = [
> 'django.middleware.security.SecurityMiddleware',
> 'django.contrib.sessions.middleware.SessionMiddleware',
> 'django.middleware.common.CommonMiddleware',
> 'django.middleware.csrf.CsrfViewMiddleware',
> 'django.contrib.auth.middleware.AuthenticationMiddleware',
> 'django.contrib.messages.middleware.MessageMiddleware',
> 'django.middleware.clickjacking.XFrameOptionsMiddleware',
> ]
> 
> ROOT_URLCONF = 'eventus.urls'
> 
> TEMPLATES = [
> {
> 'BACKEND': 'django.template.backends.django.DjangoTemplates',
> 'DIRS': [],
> 'APP_DIRS': True,
> 'OPTIONS': {
> 'context_processors': [
> 'django.template.context_processors.debug',
> 'django.template.context_processors.request',
> 'django.contrib.auth.context_processors.auth',
> 'django.contrib.messages.context_processors.messages',
> ],
> },
> },
> ]
> 
> WSGI_APPLICATION = 'eventus.wsgi.application'
> 
> 
> # Password validation
> # 
> https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
> 
> AUTH_PASSWORD_VALIDATORS = [
> {
> 'NAME': 
> 

Making chatbot

2017-09-23 Thread rakibul
Hi everyone

I want to build a chatbot app using Django Rest Framework.

-- 
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/b0b3ee57-1f3f-4ff7-bbc5-ac020eb1f990%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: capturing url pattern from html forms

2017-09-23 Thread Daniel Roseman


On Saturday, 23 September 2017 19:48:37 UTC+1, Mel DeJesus wrote:
>
>
> Hi - 
>
> If the number '1' is submitted with the form below, the following url is 
> created:  http://localhost:8000/item/?id=1
>
> But I continually get a page not found.  How can I style the regex in the 
> urlpatterns so that this url registers?  Thanks. 
>
> 
> Item Name:
> 
> 
> 
> 
>
> I'm attempting to capture here: 
>
> urlpatterns = [
> # Examples:
> url(r'^admin/', include(admin.site.urls)),
> # url(r'^item\/\?id=(?P\d+)/', views.item_detail, name='item_detail'),
> url(r'^item/(?P\d+)/', views.item_detail, name='item_detail'),
> # JSON files 
>
>
>

GET parameters are not captured in URL patterns. Just accept `^item/$` and 
get the data inside the view via `request.GET['id']`.
-- 
DR. 

-- 
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/e29da92a-14d3-4088-9a88-bd943c2e7e5b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: best practices for location of start up code

2017-09-23 Thread Larry Martell
On Sat, Sep 23, 2017 at 2:39 PM, Larry Martell  wrote:
> On Sat, Sep 23, 2017 at 1:34 PM, James Schneider
>  wrote:
>>
>>
>> On Sep 22, 2017 2:58 PM, "Larry Martell"  wrote:
>>
>> We have some code we want to run 1 time when our django app is
>> started. What is the best place for this? I tried putting it in my
>> app's config function, but from there I get:
>>
>> *** AppRegistryNotReady: Apps aren't loaded yet.
>>
>>
>> Once as in only when the app is initially deployed, or once every time the
>> web server process is started?
>>
>> Note that if you place code to run every time the web process is started,
>> that it will run for every process, and most web servers spawn multiple
>> processes.
>
> I'm looking to run it once when the web server is started (not each
> time another process of the web server is started)

I am using nginx and uwsgi. I tried experimenting with Antonis
Christofides suggestion of using AppConfig.ready(). That seems to get
called just once when I start (or restart uwsgi). I tried many
connections to the server from different browsers and computers, but
still that was only called once. Is that something I can count on?

Note, when running the devel django server it was called twice at
start up, but when the 'real' server it was only called once. Anyone
know why I got the 2 calls here?

-- 
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/CACwCsY4VDKy2H2-znVSJWG-a0rG%3DMQ8KxhvAnyLHtJPXdze1_A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


capturing url pattern from html forms

2017-09-23 Thread Mel DeJesus

Hi - 

If the number '1' is submitted with the form below, the following url is 
created:  http://localhost:8000/item/?id=1

But I continually get a page not found.  How can I style the regex in the 
urlpatterns so that this url registers?  Thanks. 


Item Name:





I'm attempting to capture here: 

urlpatterns = [
# Examples:
url(r'^admin/', include(admin.site.urls)),
# url(r'^item\/\?id=(?P\d+)/', views.item_detail, name='item_detail'),
url(r'^item/(?P\d+)/', views.item_detail, name='item_detail'),
# JSON files 






-- 
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/0f8a8292-9cbb-42fc-8bc3-d3b7f7e2e694%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: best practices for location of start up code

2017-09-23 Thread Larry Martell
On Sat, Sep 23, 2017 at 1:34 PM, James Schneider
 wrote:
>
>
> On Sep 22, 2017 2:58 PM, "Larry Martell"  wrote:
>
> We have some code we want to run 1 time when our django app is
> started. What is the best place for this? I tried putting it in my
> app's config function, but from there I get:
>
> *** AppRegistryNotReady: Apps aren't loaded yet.
>
>
> Once as in only when the app is initially deployed, or once every time the
> web server process is started?
>
> Note that if you place code to run every time the web process is started,
> that it will run for every process, and most web servers spawn multiple
> processes.

I'm looking to run it once when the web server is started (not each
time another process of the web server is started)

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


Re: best practices for location of start up code

2017-09-23 Thread James Schneider
On Sep 22, 2017 2:58 PM, "Larry Martell"  wrote:

We have some code we want to run 1 time when our django app is
started. What is the best place for this? I tried putting it in my
app's config function, but from there I get:

*** AppRegistryNotReady: Apps aren't loaded yet.


Once as in only when the app is initially deployed, or once every time the
web server process is started?

Note that if you place code to run every time the web process is started,
that it will run for every process, and most web servers spawn multiple
processes.

-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%2BciVJfED96iFyiWHThN644GXRkBXWOqkFCkvVXA8WMihJFg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: ASGI alongside mod_wsgi behind an Nginx proxy

2017-09-23 Thread Andrew Godwin
Hi there,

This is a current bug with the root path setting - see
https://github.com/django/daphne/issues/125. Until it's fixed, I'd
recommend just coding all URLs as absolute and making nginx pass them
through as such.

Andrew

On Fri, Sep 22, 2017 at 2:13 PM, Sean F  wrote:

> Hi all,
>
> I'm trying use Channels to add websockets functionality to an existing
> Django project.
>
> At this stage, my websockets functionality is a simple echo of whatever
> text is sent by the client.
>
> The  existing project runs on http://domain.com/, served by
> Apache+mod_wsgi behind a Nginx front-end proxy.
>
> I'm trying to route websockets to http://domain.com/ws/, served by daphne
> behind the same Nginx front-end proxy.
>
> The Nginx config looks like this:
>
>   # daphne
>   location /ws/ {
>   proxy_pass  http://localhost:2;
>   proxy_http_version 1.1;
>   proxy_set_header Upgrade $http_upgrade;
>   proxy_set_header Connection "upgrade";
>   }
>
>   # apache+mod_wsgi
>   location / {
>   proxy_pass  http://localhost:1;
>   }
>
> When I do this, I can connect to the websocket on http://domain.com/ws/,
> but nothing gets echoed back.
>
> Here's what I see from daphne in the console:
>
>   2017-09-22 16:52:44,654 DEBUGWebSocket 
> daphne.response.npTbOappnj!BnXbgObcDS
> open and established
>   127.0.0.1:43270 - - [22/Sep/2017:16:52:44] "WSCONNECT /" - -
>   2017-09-22 16:52:44,654 DEBUGWebSocket 
> daphne.response.npTbOappnj!BnXbgObcDS
> accepted by application
>   2017-09-22 16:52:52,569 DEBUGWebSocket incoming frame on
> daphne.response.npTbOappnj!BnXbgObcDS
>   2017-09-22 16:52:54,539 DEBUGWebSocket incoming frame on
> daphne.response.npTbOappnj!BnXbgObcDS
>   2017-09-22 16:52:55,229 DEBUGWebSocket incoming frame on
> daphne.response.npTbOappnj!BnXbgObcDS
>   2017-09-22 16:52:55,703 DEBUGWebSocket incoming frame on
> daphne.response.npTbOappnj!BnXbgObcDS
>
> The "WebSocket incoming frame on..." entries were logged each time my WS
> client sent a message.
>
> I thought "WSCONNECT /" looked suspicious, since I'm trying to connect to
> "/ws", so I tried connecting to http://domain.com/ws/ws/ instead.
>
> Sure enough, the echo worked when connected to http://domain.com/ws/ws/,
> and requests were logged as /ws.
>
> So I think the problem seems to be that daphne isn't aware that it's
> running on a sub-path /ws.
>
> I tried using the root-path parameter documented here
> https://github.com/django/daphne#root-path-script_name but that had no
> effect. The connections were still logged as / instead of /ws, and nothing
> gets echoed back.
>
> As a test, I reconfigured Nginx to serve the whole site from daphne, eg:
>
>   location / {
>   proxy_pass  http://localhost:2;
>   proxy_http_version 1.1;
>   proxy_set_header Upgrade $http_upgrade;
>   proxy_set_header Connection "upgrade";
>   }
>
> The app worked perfectly in that configuration - but I really need this to
> work alongside mod_wsgi.
>
> The docs at https://channels.readthedocs.io/en/stable/deploying.html#
> running-asgi-alongside-wsgi specifically state that this is possible:
>
> To do this, just set up your Daphne to serve as we discussed above, and
>> then configure your load-balancer or front HTTP server process to dispatch
>> requests to the correct server - based on either path, domain, or if you
>> can, the Upgrade header.
>
>
>
> Dispatching based on path or domain means you’ll need to design your
>> WebSocket URLs carefully so you can always tell how to route them at the
>> load-balancer level; the ideal thing is to be able to look for the Upgrade:
>> WebSocket header and distinguish connections by this, but not all software
>> supports this and it doesn’t help route long-poll HTTP connections at all.
>
>
> I suspect what's tripping me up is the "dispatching based on path or
> domain means you’ll need to design your WebSocket URLs carefully" bit, but
> so far I can't see what I'm doing wrong.
>
> My project is structured like this:
>
>   myproject
>   ├── db.sqlite3
>   ├── manage.py
>   ├── myapp
>   │   ├── admin.py
>   │   ├── apps.py
>   │   ├── consumers.py
>   │   ├── __init__.py
>   │   ├── migrations
>   │   │   ├── __init__.py
>   │   ├── models.py
>   │   ├── routing.py
>   │   ├── tests.py
>   │   └── views.py
>   └── myproject
>   ├── asgi.py
>   ├── __init__.py
>   ├── routing.py
>   ├── settings.py
>   ├── urls.py
>   └── wsgi.py
>
> myproject is a default Django project, and myapp is a default Django app,
> both with the minimum extra bits required for Channels.
>
> myproject/asgi.py is:
>
>   import os
>   from channels.asgi import get_channel_layer
>   os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")
>   channel_layer = get_channel_layer()
>
>
> myproject/settings.py CHANNEL_LAYERS has this:
>
>   "ROUTING": "myproject.routing.channel_routing",
>
>
> myproject/routing.py has this:
>
>   channel_routing 

First steps in Django 1.11.5 and I have my first error

2017-09-23 Thread Diego Muiño Orallo
Hello, this is my first app in Django and I have the next error:
When I launch python manage.py runserver --settings=eventus.settings.local 
apear this error:

Unhandled exception in thread started by .wrapper at 0x110c72158>

Traceback (most recent call last):

  File 
"/Users/dmuino/eventus/lib/python3.6/site-packages/django/utils/autoreload.py", 
line 228, in wrapper

fn(*args, **kwargs)

  File 
"/Users/dmuino/eventus/lib/python3.6/site-packages/django/core/management/commands/runserver.py",
 
line 117, in inner_run

autoreload.raise_last_exception()

  File 
"/Users/dmuino/eventus/lib/python3.6/site-packages/django/utils/autoreload.py", 
line 251, in raise_last_exception

six.reraise(*_exception)

  File 
"/Users/dmuino/eventus/lib/python3.6/site-packages/django/utils/six.py", 
line 685, in reraise

raise value.with_traceback(tb)

  File 
"/Users/dmuino/eventus/lib/python3.6/site-packages/django/utils/autoreload.py", 
line 228, in wrapper

fn(*args, **kwargs)

  File 
"/Users/dmuino/eventus/lib/python3.6/site-packages/django/__init__.py", 
line 27, in setup

apps.populate(settings.INSTALLED_APPS)

  File 
"/Users/dmuino/eventus/lib/python3.6/site-packages/django/apps/registry.py", 
line 85, in populate

app_config = AppConfig.create(entry)

  File 
"/Users/dmuino/eventus/lib/python3.6/site-packages/django/apps/config.py", 
line 120, in create

mod = import_module(mod_path)

  File "/Users/dmuino/eventus/lib/python3.6/importlib/__init__.py", line 
126, in import_module

return _bootstrap._gcd_import(name[level:], package, level)

  File "", line 978, in _gcd_import

  File "", line 961, in _find_and_load

  File "", line 948, in _find_and_load_unlocked

ModuleNotFoundError: No module named 'myapps'

I separated my setting for different archives.
My setting/base.py is:
"""
Django settings for eventus project.

Generated by 'django-admin startproject' using Django 1.11.5.

For more information on this file, see
https://docs.djangoproject.com/en/1.11/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.11/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'vmtu6=u+a-c_qle*+m(kwjpr$n^0ecb&5r0!#=l0vmvw_4j3tn'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

DJANGO_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]

LOCAL_APPS = [
'myapps.events',
]

THIRD_PARTY_APPS = [
]

INSTALLED_APPS = DJANGO_APPS + LOCAL_APPS + THIRD_PARTY_APPS

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'eventus.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'eventus.wsgi.application'


# Password validation
# 
https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 
'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 
'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 
'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 
'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]


# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/

and my settings/local.py
from .base import *

# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 

Re: best practices for location of start up code

2017-09-23 Thread Antonis Christofides
Hi,

I believe that the standard place for this is AppConfig.ready()
.

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com

On 2017-09-23 00:57, Larry Martell wrote:
> We have some code we want to run 1 time when our django app is
> started. What is the best place for this? I tried putting it in my
> app's config function, but from there I get:
>
> *** AppRegistryNotReady: Apps aren't loaded yet.
>

-- 
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/2b203889-c48c-bad8-52ee-14aed5bfada8%40djangodeployment.com.
For more options, visit https://groups.google.com/d/optout.