Re: Localtunnel with my Django Project

2017-10-29 Thread shreekant bohra
Hi

You don't need to integrate localtunnel with django. Open django test
server in one terminal and issue localtunnel command in another -

lt --port 8000

Above command will expose port number 8000 on internet, which is the port
of your django test server and you can test as required.


--
Shree Kant Bohra
Co-founder
Geekybuddha Technologies




On Mon, Oct 30, 2017 at 3:09 AM, yingi keme  wrote:

> Hello
>
> I need to test a service that uses Webhooks - HTTP callbacks.
>
> I want to use localtunnel to open my localhost to the internet. However i
> dont know how to integrate it with my django project. I also dont know how
> to set up the url patterns if i am to use localtunnel.
>
> Any help please...!!!
>
> --
> 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/ad8fdd20-95f3-4868-a17f-580dd54a800d%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/CAD5EYcq%3DhHU8aGAK0hu_pSdLijCFKX%3DdEYdH%2B_9v%2BRse5igOSQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Following tutoria: View not defined

2017-10-29 Thread yingi keme
Okkk. From your url pattern, What you should do is http://127.0.0.1:8000/hello. 
Because your url pattern says r'^hello/$'

But what u are doing presently is 

http://127.0.0.1:8000/

In this case your url pattern is supposed to be r'^$' and not r'^hello/$'


Yingi Kem

> On 29 Oct 2017, at 10:51 PM, Andre Basel  wrote:
> 
> Hi all
> 
> I see that I missed the import.
> 
> I now have 
> from django.conf.urls import url
> from django.contrib import admin
> 
> from mysite.views import hello
> 
> urlpatterns = [
> url(r'^admin/', admin.site.urls),
> url(r'^hello/$', hello),
> ]
> 
> 
> But get the following error in my browser now
> Page not found (404)
> Request Method:   GET
> Request URL:  http://127.0.0.1:8000/
>   Using the URLconf defined in mysite.urls,
>   Django tried these URL patterns, in this order: 
> 
> ^admin/
> 
> ^hello/$
> The empty path didn't match any of these
> 
> 
>   You're seeing this error because you have DEBUG = True in
>   your Django settings file. Change that to False, and Django
>   will display a standard 404 page.
>
> 
> 
> 
> 
>> On Monday, October 30, 2017 at 10:29:36 AM UTC+13, Oğuzhan Arslan wrote:
>> import views method in urls.py file like this:
>> 
>> 
>> from django.conf.urls import url
>> from django.contrib import admin
>> 
>> from yourapp.views import hello # <<
>> 
>> urlpatterns = [
>> url(r'^admin/', admin.site.urls),
>> url(r'^hello/$', hello),
>> ]
>> 
>> 
>> 29 Ekim 2017 Pazar 23:39:12 UTC+3 tarihinde Andre Basel yazdı:
>>> 
>>> I am totally new to Django, and working through the following tutorial 
>>> https://djangobook.com/views-urlconfs/
>>> 
>>> Ihavecreatddf the following view in views.py
>>> 
>>> from django.http import HttpResponse
>>> 
>>> def hello(request):
>>> return HttpResponse("Hello world")
>>> 
>>> 
>>>  And then as per the tutorial updated urls.py as follows:
>>> from django.conf.urls import url
>>> from django.contrib import admin
>>> 
>>> urlpatterns = [
>>> url(r'^admin/', admin.site.urls),
>>> url(r'^hello/$', hello),
>>> ]
>>> 
>>> 
>>>  When I try an browse http://127.0.0.1:8000/ I now no can no longer connect 
>>> and the console shows the following error.
>>> 
>>> System check identified no issues (0 silenced).
>>> October 29, 2017 - 20:14:10
>>> Django version 1.11.6, using settings 'mysite.settings'
>>> Starting development server at http://127.0.0.1:8000/
>>> Quit the server with CONTROL-C.
>>> [29/Oct/2017 20:14:14] "GET / HTTP/1.1" 200 1716
>>> Performing system checks...
>>> 
>>> Unhandled exception in thread started by >> check_errors..wrapper at 0x7f1eae0c4268>
>>> Traceback (most recent call last):
>>>   File 
>>> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/utils/autoreload.py",
>>>  line 228, in wrapper
>>> fn(*args, **kwargs)
>>>   File 
>>> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/management/commands/runserver.py",
>>>  line 125, in inner_run
>>> self.check(display_num_errors=True)
>>>   File 
>>> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/management/base.py",
>>>  line 359, in check
>>> include_deployment_checks=include_deployment_checks,
>>>   File 
>>> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/management/base.py",
>>>  line 346, in _run_checks
>>> return checks.run_checks(**kwargs)
>>>   File 
>>> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/checks/registry.py",
>>>  line 81, in run_checks
>>> new_errors = check(app_configs=app_configs)
>>>   File 
>>> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/checks/urls.py",
>>>  line 16, in check_url_config
>>> return check_resolver(resolver)
>>>   File 
>>> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/checks/urls.py",
>>>  line 26, in check_resolver
>>> return check_method()
>>>   File 
>>> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/urls/resolvers.py",
>>>  line 254, in check
>>> for pattern in self.url_patterns:
>>>   File 
>>> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/utils/functional.py",
>>>  line 35, in __get__
>>> res = instance.__dict__[self.name] = self.func(instance)
>>>   File 
>>> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/urls/resolvers.py",
>>>  line 405, in url_patterns
>>> patterns = getattr(self.urlconf_module, "urlpatterns", 
>>> self.urlconf_module)
>>>   File 
>>> 

Re: Following tutoria: View not defined

2017-10-29 Thread Andre Basel
Thanks again :)

That was it. 

On Monday, October 30, 2017 at 10:56:34 AM UTC+13, cjacq...@gmail.com wrote:
>
> Did you try http://127.0.0.1:8000/hello/ ?
>
> Le dimanche 29 octobre 2017 21:39:12 UTC+1, Andre Basel a écrit :
>>
>> I am totally new to Django, and working through the following tutorial 
>> https://djangobook.com/views-urlconfs/
>>
>> Ihavecreatddf the following view in views.py
>>
>> from django.http import HttpResponse
>>
>> def hello(request):
>> return HttpResponse("Hello world")
>>
>>
>>  And then as per the tutorial updated urls.py as follows:
>> from django.conf.urls import url
>> from django.contrib import admin
>>
>> urlpatterns = [
>> url(r'^admin/', admin.site.urls),
>> url(r'^hello/$', hello),
>> ]
>>
>>
>>  When I try an browse http://127.0.0.1:8000/ I now no can no longer 
>> connect and the console shows the following error.
>>
>> System check identified no issues (0 silenced).
>> October 29, 2017 - 20:14:10
>> Django version 1.11.6, using settings 'mysite.settings'
>> Starting development server at http://127.0.0.1:8000/
>> Quit the server with CONTROL-C.
>> [29/Oct/2017 20:14:14] "GET / HTTP/1.1" 200 1716
>> Performing system checks...
>>
>> Unhandled exception in thread started by > check_errors..wrapper 
>> at 0x7f1eae0c4268>
>> Traceback (most recent call last):
>>   File 
>> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/utils/autoreload.py"
>> , line 228, in wrapper
>> fn(*args, **kwargs)
>>   File 
>> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/management/commands/runserver.py"
>> , line 125, in inner_run
>> self.check(display_num_errors=True)
>>   File 
>> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/management/base.py"
>> , line 359, in check
>> include_deployment_checks=include_deployment_checks,
>>   File 
>> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/management/base.py"
>> , line 346, in _run_checks
>> return checks.run_checks(**kwargs)
>>   File 
>> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/checks/registry.py"
>> , line 81, in run_checks
>> new_errors = check(app_configs=app_configs)
>>   File 
>> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/checks/urls.py"
>> , line 16, in check_url_config
>> return check_resolver(resolver)
>>   File 
>> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/checks/urls.py"
>> , line 26, in check_resolver
>> return check_method()
>>   File 
>> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/urls/resolvers.py"
>> , line 254, in check
>> for pattern in self.url_patterns:
>>   File 
>> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/utils/functional.py"
>> , line 35, in __get__
>> res = instance.__dict__[self.name] = self.func(instance)
>>   File 
>> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/urls/resolvers.py"
>> , line 405, in url_patterns
>> patterns = getattr(self.urlconf_module, "urlpatterns", self.
>> urlconf_module)
>>   File 
>> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/utils/functional.py"
>> , line 35, in __get__
>> res = instance.__dict__[self.name] = self.func(instance)
>>   File 
>> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/urls/resolvers.py"
>> , line 398, in urlconf_module
>> return import_module(self.urlconf_name)
>>   File "/usr/lib64/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 950, in 
>> _find_and_load_unlocked
>>   File "", line 655, in _load_unlocked
>>   File "", line 678, in exec_module
>>   File "", line 205, in 
>> _call_with_frames_removed
>>   File 
>> "/home/abasel/Dajango_Projects/my_first_project/mysite/mysite/urls.py", 
>> line 21, in 
>> url(r'^hello/$', hello),
>> NameError: name 'hello' is not defined
>>
>> I am not sure how to proceed.
>>
>

-- 
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 

Re: Following tutoria: View not defined

2017-10-29 Thread cjacquemet
Did you try http://127.0.0.1:8000/hello/ ?

Le dimanche 29 octobre 2017 21:39:12 UTC+1, Andre Basel a écrit :
>
> I am totally new to Django, and working through the following tutorial 
> https://djangobook.com/views-urlconfs/
>
> Ihavecreatddf the following view in views.py
>
> from django.http import HttpResponse
>
> def hello(request):
> return HttpResponse("Hello world")
>
>
>  And then as per the tutorial updated urls.py as follows:
> from django.conf.urls import url
> from django.contrib import admin
>
> urlpatterns = [
> url(r'^admin/', admin.site.urls),
> url(r'^hello/$', hello),
> ]
>
>
>  When I try an browse http://127.0.0.1:8000/ I now no can no longer 
> connect and the console shows the following error.
>
> System check identified no issues (0 silenced).
> October 29, 2017 - 20:14:10
> Django version 1.11.6, using settings 'mysite.settings'
> Starting development server at http://127.0.0.1:8000/
> Quit the server with CONTROL-C.
> [29/Oct/2017 20:14:14] "GET / HTTP/1.1" 200 1716
> Performing system checks...
>
> Unhandled exception in thread started by  check_errors..wrapper 
> at 0x7f1eae0c4268>
> Traceback (most recent call last):
>   File 
> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/utils/autoreload.py"
> , line 228, in wrapper
> fn(*args, **kwargs)
>   File 
> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/management/commands/runserver.py"
> , line 125, in inner_run
> self.check(display_num_errors=True)
>   File 
> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/management/base.py"
> , line 359, in check
> include_deployment_checks=include_deployment_checks,
>   File 
> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/management/base.py"
> , line 346, in _run_checks
> return checks.run_checks(**kwargs)
>   File 
> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/checks/registry.py"
> , line 81, in run_checks
> new_errors = check(app_configs=app_configs)
>   File 
> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/checks/urls.py"
> , line 16, in check_url_config
> return check_resolver(resolver)
>   File 
> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/checks/urls.py"
> , line 26, in check_resolver
> return check_method()
>   File 
> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/urls/resolvers.py"
> , line 254, in check
> for pattern in self.url_patterns:
>   File 
> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/utils/functional.py"
> , line 35, in __get__
> res = instance.__dict__[self.name] = self.func(instance)
>   File 
> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/urls/resolvers.py"
> , line 405, in url_patterns
> patterns = getattr(self.urlconf_module, "urlpatterns", self.
> urlconf_module)
>   File 
> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/utils/functional.py"
> , line 35, in __get__
> res = instance.__dict__[self.name] = self.func(instance)
>   File 
> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/urls/resolvers.py"
> , line 398, in urlconf_module
> return import_module(self.urlconf_name)
>   File "/usr/lib64/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 950, in 
> _find_and_load_unlocked
>   File "", line 655, in _load_unlocked
>   File "", line 678, in exec_module
>   File "", line 205, in 
> _call_with_frames_removed
>   File 
> "/home/abasel/Dajango_Projects/my_first_project/mysite/mysite/urls.py", 
> line 21, in 
> url(r'^hello/$', hello),
> NameError: name 'hello' is not defined
>
> I am not sure how to proceed.
>

-- 
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/b4bb58ab-bfbc-479e-a2f1-85165e1f0c70%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Following tutoria: View not defined

2017-10-29 Thread Andre Basel
Hi all

I see that I missed the import.

I now have 
from django.conf.urls import url
from django.contrib import admin

from mysite.views import hello

urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^hello/$', hello),
]


But get the following error in my browser now
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/   Using the URLconf defined in 
mysite.urls,

  Django tried these URL patterns, in this order: 

   1. ^admin/
   
   2. ^hello/$
   
The empty path didn't match any of these

  You're seeing this error because you have DEBUG = True in
  your Django settings file. Change that to False, and Django
  will display a standard 404 page.
   



On Monday, October 30, 2017 at 10:29:36 AM UTC+13, Oğuzhan Arslan wrote:
>
> import views method in urls.py file like this:
>
>
> from django.conf.urls import url
> from django.contrib import admin
>
> from yourapp.views import *hello* # <<
>
> urlpatterns = [
> url(r'^admin/', admin.site.urls),
> url(r'^hello/$', hello),
> ]
>
>
> 29 Ekim 2017 Pazar 23:39:12 UTC+3 tarihinde Andre Basel yazdı:
>>
>> I am totally new to Django, and working through the following tutorial 
>> https://djangobook.com/views-urlconfs/
>>
>> Ihavecreatddf the following view in views.py
>>
>> from django.http import HttpResponse
>>
>> def hello(request):
>> return HttpResponse("Hello world")
>>
>>
>>  And then as per the tutorial updated urls.py as follows:
>> from django.conf.urls import url
>> from django.contrib import admin
>>
>> urlpatterns = [
>> url(r'^admin/', admin.site.urls),
>> url(r'^hello/$', hello),
>> ]
>>
>>
>>  When I try an browse http://127.0.0.1:8000/ I now no can no longer 
>> connect and the console shows the following error.
>>
>> System check identified no issues (0 silenced).
>> October 29, 2017 - 20:14:10
>> Django version 1.11.6, using settings 'mysite.settings'
>> Starting development server at http://127.0.0.1:8000/
>> Quit the server with CONTROL-C.
>> [29/Oct/2017 20:14:14] "GET / HTTP/1.1" 200 1716
>> Performing system checks...
>>
>> Unhandled exception in thread started by > check_errors..wrapper 
>> at 0x7f1eae0c4268>
>> Traceback (most recent call last):
>>   File 
>> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/utils/autoreload.py"
>> , line 228, in wrapper
>> fn(*args, **kwargs)
>>   File 
>> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/management/commands/runserver.py"
>> , line 125, in inner_run
>> self.check(display_num_errors=True)
>>   File 
>> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/management/base.py"
>> , line 359, in check
>> include_deployment_checks=include_deployment_checks,
>>   File 
>> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/management/base.py"
>> , line 346, in _run_checks
>> return checks.run_checks(**kwargs)
>>   File 
>> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/checks/registry.py"
>> , line 81, in run_checks
>> new_errors = check(app_configs=app_configs)
>>   File 
>> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/checks/urls.py"
>> , line 16, in check_url_config
>> return check_resolver(resolver)
>>   File 
>> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/checks/urls.py"
>> , line 26, in check_resolver
>> return check_method()
>>   File 
>> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/urls/resolvers.py"
>> , line 254, in check
>> for pattern in self.url_patterns:
>>   File 
>> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/utils/functional.py"
>> , line 35, in __get__
>> res = instance.__dict__[self.name] = self.func(instance)
>>   File 
>> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/urls/resolvers.py"
>> , line 405, in url_patterns
>> patterns = getattr(self.urlconf_module, "urlpatterns", self.
>> urlconf_module)
>>   File 
>> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/utils/functional.py"
>> , line 35, in __get__
>> res = instance.__dict__[self.name] = self.func(instance)
>>   File 
>> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/urls/resolvers.py"
>> , line 398, in urlconf_module
>> return import_module(self.urlconf_name)
>>   File "/usr/lib64/python3.6/importlib/__init__.py", line 126, in 
>> import_module
>> return _bootstrap._gcd_import(name[level:], package, level)
>>   File "", line 978, in 

Localtunnel with my Django Project

2017-10-29 Thread yingi keme
Hello

I need to test a service that uses Webhooks - HTTP callbacks.

I want to use localtunnel to open my localhost to the internet. However i dont 
know how to integrate it with my django project. I also dont know how to set up 
the url patterns if i am to use localtunnel.

Any help please...!!!

-- 
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/ad8fdd20-95f3-4868-a17f-580dd54a800d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Following tutoria: View not defined

2017-10-29 Thread Oğuzhan Arslan
import views method in urls.py file like this:


from django.conf.urls import url
from django.contrib import admin

from yourapp.views import *hello* # <<

urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^hello/$', hello),
]


29 Ekim 2017 Pazar 23:39:12 UTC+3 tarihinde Andre Basel yazdı:
>
> I am totally new to Django, and working through the following tutorial 
> https://djangobook.com/views-urlconfs/
>
> Ihavecreatddf the following view in views.py
>
> from django.http import HttpResponse
>
> def hello(request):
> return HttpResponse("Hello world")
>
>
>  And then as per the tutorial updated urls.py as follows:
> from django.conf.urls import url
> from django.contrib import admin
>
> urlpatterns = [
> url(r'^admin/', admin.site.urls),
> url(r'^hello/$', hello),
> ]
>
>
>  When I try an browse http://127.0.0.1:8000/ I now no can no longer 
> connect and the console shows the following error.
>
> System check identified no issues (0 silenced).
> October 29, 2017 - 20:14:10
> Django version 1.11.6, using settings 'mysite.settings'
> Starting development server at http://127.0.0.1:8000/
> Quit the server with CONTROL-C.
> [29/Oct/2017 20:14:14] "GET / HTTP/1.1" 200 1716
> Performing system checks...
>
> Unhandled exception in thread started by  check_errors..wrapper 
> at 0x7f1eae0c4268>
> Traceback (most recent call last):
>   File 
> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/utils/autoreload.py"
> , line 228, in wrapper
> fn(*args, **kwargs)
>   File 
> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/management/commands/runserver.py"
> , line 125, in inner_run
> self.check(display_num_errors=True)
>   File 
> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/management/base.py"
> , line 359, in check
> include_deployment_checks=include_deployment_checks,
>   File 
> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/management/base.py"
> , line 346, in _run_checks
> return checks.run_checks(**kwargs)
>   File 
> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/checks/registry.py"
> , line 81, in run_checks
> new_errors = check(app_configs=app_configs)
>   File 
> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/checks/urls.py"
> , line 16, in check_url_config
> return check_resolver(resolver)
>   File 
> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/checks/urls.py"
> , line 26, in check_resolver
> return check_method()
>   File 
> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/urls/resolvers.py"
> , line 254, in check
> for pattern in self.url_patterns:
>   File 
> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/utils/functional.py"
> , line 35, in __get__
> res = instance.__dict__[self.name] = self.func(instance)
>   File 
> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/urls/resolvers.py"
> , line 405, in url_patterns
> patterns = getattr(self.urlconf_module, "urlpatterns", self.
> urlconf_module)
>   File 
> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/utils/functional.py"
> , line 35, in __get__
> res = instance.__dict__[self.name] = self.func(instance)
>   File 
> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/urls/resolvers.py"
> , line 398, in urlconf_module
> return import_module(self.urlconf_name)
>   File "/usr/lib64/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 950, in 
> _find_and_load_unlocked
>   File "", line 655, in _load_unlocked
>   File "", line 678, in exec_module
>   File "", line 205, in 
> _call_with_frames_removed
>   File 
> "/home/abasel/Dajango_Projects/my_first_project/mysite/mysite/urls.py", 
> line 21, in 
> url(r'^hello/$', hello),
> NameError: name 'hello' is not defined
>
> I am not sure how to proceed.
>

-- 
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 

Datefield model not show Today and Calender options in Admin page

2017-10-29 Thread Oğuzhan Arslan
Why Today and Calender option do not show in admin page ? This fields 
calender and Today option displayed two days ago. 

-- 
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/0320f344-867e-4d32-821b-8ff8cc24ee4c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Following tutoria: View not defined

2017-10-29 Thread cjacquemet
Hi ! You have to import your view.

Like this :

from .views import hello


Le dimanche 29 octobre 2017 21:39:12 UTC+1, Andre Basel a écrit :
>
> I am totally new to Django, and working through the following tutorial 
> https://djangobook.com/views-urlconfs/
>
> Ihavecreatddf the following view in views.py
>
> from django.http import HttpResponse
>
> def hello(request):
> return HttpResponse("Hello world")
>
>
>  And then as per the tutorial updated urls.py as follows:
> from django.conf.urls import url
> from django.contrib import admin
>
> urlpatterns = [
> url(r'^admin/', admin.site.urls),
> url(r'^hello/$', hello),
> ]
>
>
>  When I try an browse http://127.0.0.1:8000/ I now no can no longer 
> connect and the console shows the following error.
>
> System check identified no issues (0 silenced).
> October 29, 2017 - 20:14:10
> Django version 1.11.6, using settings 'mysite.settings'
> Starting development server at http://127.0.0.1:8000/
> Quit the server with CONTROL-C.
> [29/Oct/2017 20:14:14] "GET / HTTP/1.1" 200 1716
> Performing system checks...
>
> Unhandled exception in thread started by  check_errors..wrapper 
> at 0x7f1eae0c4268>
> Traceback (most recent call last):
>   File 
> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/utils/autoreload.py"
> , line 228, in wrapper
> fn(*args, **kwargs)
>   File 
> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/management/commands/runserver.py"
> , line 125, in inner_run
> self.check(display_num_errors=True)
>   File 
> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/management/base.py"
> , line 359, in check
> include_deployment_checks=include_deployment_checks,
>   File 
> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/management/base.py"
> , line 346, in _run_checks
> return checks.run_checks(**kwargs)
>   File 
> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/checks/registry.py"
> , line 81, in run_checks
> new_errors = check(app_configs=app_configs)
>   File 
> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/checks/urls.py"
> , line 16, in check_url_config
> return check_resolver(resolver)
>   File 
> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/checks/urls.py"
> , line 26, in check_resolver
> return check_method()
>   File 
> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/urls/resolvers.py"
> , line 254, in check
> for pattern in self.url_patterns:
>   File 
> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/utils/functional.py"
> , line 35, in __get__
> res = instance.__dict__[self.name] = self.func(instance)
>   File 
> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/urls/resolvers.py"
> , line 405, in url_patterns
> patterns = getattr(self.urlconf_module, "urlpatterns", self.
> urlconf_module)
>   File 
> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/utils/functional.py"
> , line 35, in __get__
> res = instance.__dict__[self.name] = self.func(instance)
>   File 
> "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/urls/resolvers.py"
> , line 398, in urlconf_module
> return import_module(self.urlconf_name)
>   File "/usr/lib64/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 950, in 
> _find_and_load_unlocked
>   File "", line 655, in _load_unlocked
>   File "", line 678, in exec_module
>   File "", line 205, in 
> _call_with_frames_removed
>   File 
> "/home/abasel/Dajango_Projects/my_first_project/mysite/mysite/urls.py", 
> line 21, in 
> url(r'^hello/$', hello),
> NameError: name 'hello' is not defined
>
> I am not sure how to proceed.
>

-- 
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/5b953bd2-aa19-49b9-89b1-0358bdc7da3f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Following tutoria: View not defined

2017-10-29 Thread Andre Basel
I am totally new to Django, and working through the following tutorial 
https://djangobook.com/views-urlconfs/

Ihavecreatddf the following view in views.py

from django.http import HttpResponse

def hello(request):
return HttpResponse("Hello world")


 And then as per the tutorial updated urls.py as follows:
from django.conf.urls import url
from django.contrib import admin

urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^hello/$', hello),
]


 When I try an browse http://127.0.0.1:8000/ I now no can no longer connect 
and the console shows the following error.

System check identified no issues (0 silenced).
October 29, 2017 - 20:14:10
Django version 1.11.6, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[29/Oct/2017 20:14:14] "GET / HTTP/1.1" 200 1716
Performing system checks...

Unhandled exception in thread started by .wrapper 
at 0x7f1eae0c4268>
Traceback (most recent call last):
  File 
"/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/utils/autoreload.py"
, line 228, in wrapper
fn(*args, **kwargs)
  File 
"/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/management/commands/runserver.py"
, line 125, in inner_run
self.check(display_num_errors=True)
  File 
"/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/management/base.py"
, line 359, in check
include_deployment_checks=include_deployment_checks,
  File 
"/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/management/base.py"
, line 346, in _run_checks
return checks.run_checks(**kwargs)
  File 
"/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/checks/registry.py"
, line 81, in run_checks
new_errors = check(app_configs=app_configs)
  File 
"/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/checks/urls.py"
, line 16, in check_url_config
return check_resolver(resolver)
  File 
"/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/checks/urls.py"
, line 26, in check_resolver
return check_method()
  File 
"/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/urls/resolvers.py"
, line 254, in check
for pattern in self.url_patterns:
  File 
"/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/utils/functional.py"
, line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
  File 
"/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/urls/resolvers.py"
, line 405, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.
urlconf_module)
  File 
"/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/utils/functional.py"
, line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
  File 
"/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/urls/resolvers.py"
, line 398, in urlconf_module
return import_module(self.urlconf_name)
  File "/usr/lib64/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 950, in _find_and_load_unlocked
  File "", line 655, in _load_unlocked
  File "", line 678, in exec_module
  File "", line 205, in 
_call_with_frames_removed
  File 
"/home/abasel/Dajango_Projects/my_first_project/mysite/mysite/urls.py", 
line 21, in 
url(r'^hello/$', hello),
NameError: name 'hello' is not defined

I am not sure how to proceed.

-- 
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/d16c458d-4cf9-40ed-861b-b19a8cd2f02c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: return jwt token as json

2017-10-29 Thread Jani Tiainen
As a simplest possible form you can pass jwt as s string:

"Xxx.yyyhgg.cxxch"

29.10.2017 19.33 "Rakhee Menon"  kirjoitti:

> Unable to send jwt token as json response
>
> --
> 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/742f8637-b9e2-4d13-9ea7-0764fb45f5e9%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/CAHn91ofpL2nBJUcfxgi3D7_LZy9pHiRTrx7sYPS_a_ASUbyYMw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


MultipleChoiceField is being displayed as a string instead of a list

2017-10-29 Thread Jack
I have a MultipleChoiceField forms field which shows up in the database like 
this . It seems to have been converted 
to a string in the database, because when I try to display it with a 'for 
property in property_type' statement in the HTML, it shows up like this 
. I want it to be displayed like this 
.  I have also tried using an 
ArrayField (shown below), but the result is the same.


models.py:

property_type = models.CharField(max_length=50, help_text="You can select more 
than 1 option")

property_type = ArrayField(models.CharField(max_length=50), help_text="You can 
select more than 1 option"))


forms.py:

property_type = forms.MultipleChoiceField(widget=forms.SelectMultiple, 
choices=BuyerListing.PROPERTY_TYPE)

HTML:

{% for property in listing.property_type %}
Property type: {{ property }}
{% endfor %}



How do I get this MultipleChoiceField to load as a list so I can display it 
properly with a for statement?

-- 
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/cb625aff-b96e-4a07-9737-d89805085962%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django 11 ImproperlyConfigured: AUTH_USER_MODEL refers to model 'authex.UserProfile' that has not been installed

2017-10-29 Thread cjacquemet
Hi everyone,

I'm trying to update Django from 1.10.8 to 1.11.6 but it raise me an error.

I just update Django with pip. I use Python 2.7.11 and Mac OS X and 
everything was working on Django 1.10.8.


Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/django/utils/autoreload.py", line 
228, in wrapper
fn(*args, **kwargs)
  File 
"/Library/Python/2.7/site-packages/django/core/management/commands/runserver.py",
 
line 117, in inner_run
autoreload.raise_last_exception()
  File "/Library/Python/2.7/site-packages/django/utils/autoreload.py", line 
251, in raise_last_exception
six.reraise(*_exception)
  File "/Library/Python/2.7/site-packages/django/utils/autoreload.py", line 
228, in wrapper
fn(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/django/__init__.py", line 27, in 
setup
apps.populate(settings.INSTALLED_APPS)
  File "/Library/Python/2.7/site-packages/django/apps/registry.py", line 
108, in populate
app_config.import_models()
  File "/Library/Python/2.7/site-packages/django/apps/config.py", line 202, 
in import_models
self.models_module = import_module(models_module_name)
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py",
 
line 37, in import_module
__import__(name)
  File "/Users/Colas/PyCharmProjects/assoweb/authex/models.py", line 6, in 

from django.contrib.auth.admin import UserAdmin
  File "/Library/Python/2.7/site-packages/django/contrib/auth/admin.py", 
line 7, in 
from django.contrib.auth.forms import (
  File "/Library/Python/2.7/site-packages/django/contrib/auth/forms.py", 
line 22, in 
UserModel = get_user_model()
  File "/Library/Python/2.7/site-packages/django/contrib/auth/__init__.py", 
line 198, in get_user_model
"AUTH_USER_MODEL refers to model '%s' that has not been installed" % 
settings.AUTH_USER_MODEL
django.core.exceptions.ImproperlyConfigured: AUTH_USER_MODEL refers to 
model 'authex.UserProfile' that has not been installed


Any ideas ? Thanks !

Colas

-- 
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/e10c7aef-1bd0-40dd-b899-9b707f085b12%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


return jwt token as json

2017-10-29 Thread Rakhee Menon
Unable to send jwt token as json response

-- 
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/742f8637-b9e2-4d13-9ea7-0764fb45f5e9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to get Foreign Key Objects programmatically?

2017-10-29 Thread rmschne
I'm using Django as front end to a MySQL database. User interface is a 
terminal program, not a web site.

I've written a very simple generic function to edit the fields of one 
record of a Django "object".  It works fine for editing editable fields. 
User specifies which field, then is shown the current value, raw_input() 
for the new value, then save() the record.

For fields that connect to Foreign Keys, what I want to do is present to 
user a simple list of Foreign Key records, from which the user will pick 
the relevant ID.  I know, given a list and the ID, how to then edit the 
record by doing a Django get(id=ID) on the Foreign Key table.  What I'm 
having trouble doing is figuring how

1. Identify into a variable the name of the Foreign Key table/object
2. Then with that variable do a call to the relevant Foreign Key table, 
e.g. ForeignKeyTable.objects.all()

See code below for <===WHAT I DO NOT KNOW HOW TO DO IN CODE Below.  I think 
I need some Django function that gives me the foreign key table in some 
useable generic form.

Hope all this makes sense. 

--rms

def EditDjangoObjectData(djangoobject,show=False,editonerecord=False):
"""
EditDjangoObjectData()
djangoojbect=a django object, e.g. a record in a table
"""
print "\nToDo Note: This routine not yet working on fields with 
foreign keys!"
changelist=[]
ok=True
while ok:
change=None
fields = [(f.name, f.editable) for f in 
djangoobject._meta.get_fields()]
if show:
print "\nfields:\n",fields
print "django object:\n",djangoobject
s="\nEditable Fields ('enter' to return): \n"
fieldlist=[]
for i in fields:
if i[1]:   # only for 'editable' fields
if i[0].lower() <> "id":
s=s+i[0]+", "
fieldlist.append(i[0])
s=s+"DELETE or '?'"
fieldok=False
while not fieldok:
fieldtochange=raw_input("Enter field name to change:\n"+s+": ")
if not fieldtochange:
return None
elif fieldtochange.upper()=="DELETE":
ans=raw_input("...Confirm DELETE by typing 'DELETE': ")
try:
if ans=="DELETE":
rtn=djangoobject.delete()
print "Deleted. ",rtn
return rtn
except:
print "***DELETE Failed.",sys.exc_info()[0]
ans=raw_input("Press 'Enter' to continue ... ")
elif fieldtochange=="?":
PrintObjectDetails(djangoobject)
elif fieldtochange in fieldlist:
fieldok=True
else:
print "\nError. ",fieldtochange,"is not in list. Try 
again."
print "Current Value of Field to 
Change:",fieldtochange,"is:",getattr(djangoobject, fieldtochange)
**
** In here add some code to show a list of the foreign key records for user 
to select, e.g. ID, Description, 
**for r in ForeignKey.objects.all():   <== WHAT I DO NOT KNOW HOW TO DO IN 
CODE.
**print i.id, i.description
**ID=raw_input("Enter ID:)
**foreignkeyobject=ForeignKey.objects.get(id=ID)<== WHAT I DO NOT KNOW 
HOW TO DO IN CODE.
** ... then put that object into the relevant field 
newvalue=raw_input("Enter New Value: ")
change="changed ["+fieldtochange+"]"
print "\nTo Save   :",djangoobject
print "The Change:",change,"to",newvalue
if not newvalue:
return None
elif newvalue.lower()=="none":
newvalue=None
elif newvalue.lower()=="true":
newvalue==True
elif newvalue.lower()=="false":
newvalue=False
setattr(djangoobject, fieldtochange, newvalue)
try:
djangoobject.save()
print ": Success. Saved:",change,"to",newvalue
print ": New Object:",djangoobject
changelist.append(change)
print "ChangeList:",changelist
except:
print "***Save Failed.",sys.exc_info()[0]
ans=raw_input("Press 'Enter' to continue ... ")
if editonerecord:
ok=False
return changelist

-- 
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/4028d8fa-88b8-4940-ba41-a1b47a0913ba%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Building a search form with 4 required choices, which will be inserted as arguments in an URL [warning: long question]

2017-10-29 Thread Jack
That makes much more sense.  It's my fault for not reading the Django docs 
properly, but I don't seem to soak in the concepts at all by simply 
reading.  

I went with a ListView + get_queryset override.  I haven't managed to get 
the filter to work but the search itself is working properly.

Thanks Daniel!

On Sunday, October 29, 2017 at 7:59:25 AM UTC-4, Daniel Roseman wrote:
>
> On Monday, 23 October 2017 16:59:36 UTC+1, Jack wrote:
>>
>> This is a semi-long question.  Please let me know wherever I make a 
>> mistake.
>>
>> I'm building a search form with 4 required choices, 1 of the choices is a 
>> CharField with a max_length of 3.  The other 3 choices are ChoiceField's.  
>> Here is a picture of what the search form looks like:
>>
>>
>> 
>>
>> I've read through the Django docs and other things on the Internet but 
>> I'm still very unclear about how to approach this.
>>
>> 1. First I believe I need to create 4 args or kwargs in the url for each 
>> of the choices.  If I use args, it would look something like...
>>
>> url(r'^search?(\w+{3})&(\w+{2})&(\w+{1-2})&(\w+{1-2})', function/class 
>> view, name='search')
>>
>> 2. Next, I need to pass the user's input in the html page into the url 
>> args.  I have a form set up to get the user's input.  But how would I write 
>> this on the HTML page?  Do I simply make a url tag like {% url 'search' 
>> args1, args2, args3, args4 %}?
>>
>> 3. Then I need to create the views function.  My first question is, 
>> should I use a function-based view or the generic class-based ListView?  
>> The result of the search will be a list of items, so ListView is a good 
>> template to use, but I don't know how having 4 args would affect using 
>> ListView.  My second question is, what is the most effective way of making 
>> this search?  I need to check if any records in the database matches the 
>> user's search, so would I do something like 'For record in database' to 
>> check over every record in the database?
>>
>> If I used a function view, would it look something like:
>>
>> def search(request, args1, args2, args3, args4):
>>  for record in database:
>>   if args matches record:
>>display record
>>
>> Thank you for reading through the question
>>
>
>
> Your difficulties all stem from the same misunderstanding here.
>
> Forms - at least when using the GET action - put their arguments in the 
> querystring - the bit after the ? in the URL. Django doesn't treat that as 
> part of the URL itself, but as a separate attribute, `request.GET`. So both 
> your first and second questions are irrelevant: you don't need to capture 
> the values in a URL pattern, and nor do you need to insert them in there in 
> the HTML somehow. Just use a basic pattern of `r('^search/$)` and all will 
> be fine.
>
> For your third question, it makes no difference whether you use function 
> or class-based views. If you did use a ListView, though, you could override 
> `get_queryset` to filter by the values in the GET dictionary:
>
> def get_queryset(self):
> qs = super(MyListView, self).get_queryset()
> if 'bedrooms' in request.GET:
> qs = qs.filter(bedrooms=request.GET['bedrooms']
> ... etc ...
> return qs
>
> -- 
> 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/c6bb83c1-16fd-4375-88ba-9516a9677c29%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django View classes and database selection

2017-10-29 Thread Sören Mindorf
Hi all,

I've two databases connected in my setup.
One default (sqlite) for Djano and one postgressql (pgsql, NOT managed) for
my postfix.

In my AddDomainView(CreateView) I can access the pgsql database and
I can add Domains to the pgsql-database but in my DeleteDomain(DeleteView)
I can't because the view will always try to find the table in the sqlite3
Database where it
not is.

Here parts of my code:

view.py
-%<-
# -*- coding: utf-8 -*-
import socket

from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.http.response import HttpResponseRedirect, Http404
from django.urls.base import reverse
from django.utils.decorators import method_decorator
from django.utils.translation import ugettext as _
from django.views.generic.edit import CreateView, DeleteView
from django.db.utils import IntegrityError
from vmail.domain.forms import CreateDomainForm
from vmail.main.models import Domains


class AddDomainView(CreateView):
template_name = 'domain/add_domain.html'
model = Domains
form_class = CreateDomainForm

@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
return super(AddDomainView, self).dispatch(*args, **kwargs)

def get_form(self, form_class=form_class):
form = super(AddDomainView, self).get_form(form_class)
form.fields['domain'].queryset =
Domains.objects.using('pgsql').all()
return form

def form_valid(self, form):
self.object = form.save(commit=False)
try:
socket.gethostbyname(self.object.domain)
except socket.gaierror:
success, level, msg = False, messages.ERROR, _('Base domain
does not exist.')
else:
try:
self.object.created_by = self.request.user
self.object.save(using='pgsql')
success, level, msg = True, messages.SUCCESS, _('Domain
added.')
except IntegrityError:
success, level, msg = False, messages.WARNING, _('Domain
already exists .')
messages.add_message(self.request, level, msg)
url = reverse('overview')
return HttpResponseRedirect(url)

def get_context_data(self, **kwargs):
context = super(AddDomainView, self).get_context_data(**kwargs)
context['nav_overview'] = True
return context


class DeleteDomain(DeleteView):
model = Domains
template_name = 'domain/delete_domain.html'

@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
return super(DeleteDomain, self).dispatch(*args, **kwargs)

def get_object(self, *args, **kwargs):
obj = super(DeleteDomain, self).get_object(*args, **kwargs)
if obj.created_by != self.request.user :
raise Http404
return obj

def get_success_url(self):
return reverse('overview')

def get_context_data(self, **kwargs):
context = super(DeleteDomain, self).get_context_data(**kwargs)
context['nav_overview'] = True
return context
->%-

settings.py
-%<-
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
},
'pgsql': {
'ENGINE': 'django.db.backends.postgresql',
'HOST': 'localhost',
'PORT': '5432',
'PASSWORD': 'x',
'USER': 'vmailuser',
'NAME': 'virtualmail',
'OPTIONS': {
'options': '-c search_path=public'
},
}
}
->%-

model.py:
-%<-
# -*- coding: utf-8 -*-
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.core.validators import RegexValidator


class Domains(models.Model):
id = models.AutoField(primary_key=True,
  unique=True)
domain = (
models.CharField(max_length=255,
 blank=False,
 null=True,
 validators=[RegexValidator(
 regex=r"([a-zA-Z0-9-_]+\.)+[a-zA-Z0-9-_]
 {2,}",
 message=_("Invalid domain name")
 )],
 help_text=_('Please enter the email Domain
 here')
 )
)
created_by = (
models.CharField(max_length=255)
)

class Meta:
managed = False
db_table = 'domains'

def __unicode__(self):
return self.domain
->%-

So how can I select the right database in the class-view?
And please remember, the pgsql is unmanaged in the model class. ;)

Kind regards,
Sören

-- 
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 

Re: Building a search form with 4 required choices, which will be inserted as arguments in an URL [warning: long question]

2017-10-29 Thread Daniel Roseman
On Monday, 23 October 2017 16:59:36 UTC+1, Jack wrote:
>
> This is a semi-long question.  Please let me know wherever I make a 
> mistake.
>
> I'm building a search form with 4 required choices, 1 of the choices is a 
> CharField with a max_length of 3.  The other 3 choices are ChoiceField's.  
> Here is a picture of what the search form looks like:
>
>
> 
>
> I've read through the Django docs and other things on the Internet but I'm 
> still very unclear about how to approach this.
>
> 1. First I believe I need to create 4 args or kwargs in the url for each 
> of the choices.  If I use args, it would look something like...
>
> url(r'^search?(\w+{3})&(\w+{2})&(\w+{1-2})&(\w+{1-2})', function/class 
> view, name='search')
>
> 2. Next, I need to pass the user's input in the html page into the url 
> args.  I have a form set up to get the user's input.  But how would I write 
> this on the HTML page?  Do I simply make a url tag like {% url 'search' 
> args1, args2, args3, args4 %}?
>
> 3. Then I need to create the views function.  My first question is, should 
> I use a function-based view or the generic class-based ListView?  The 
> result of the search will be a list of items, so ListView is a good 
> template to use, but I don't know how having 4 args would affect using 
> ListView.  My second question is, what is the most effective way of making 
> this search?  I need to check if any records in the database matches the 
> user's search, so would I do something like 'For record in database' to 
> check over every record in the database?
>
> If I used a function view, would it look something like:
>
> def search(request, args1, args2, args3, args4):
>  for record in database:
>   if args matches record:
>display record
>
> Thank you for reading through the question
>


Your difficulties all stem from the same misunderstanding here.

Forms - at least when using the GET action - put their arguments in the 
querystring - the bit after the ? in the URL. Django doesn't treat that as 
part of the URL itself, but as a separate attribute, `request.GET`. So both 
your first and second questions are irrelevant: you don't need to capture 
the values in a URL pattern, and nor do you need to insert them in there in 
the HTML somehow. Just use a basic pattern of `r('^search/$)` and all will 
be fine.

For your third question, it makes no difference whether you use function or 
class-based views. If you did use a ListView, though, you could override 
`get_queryset` to filter by the values in the GET dictionary:

def get_queryset(self):
qs = super(MyListView, self).get_queryset()
if 'bedrooms' in request.GET:
qs = qs.filter(bedrooms=request.GET['bedrooms']
... etc ...
return qs

-- 
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/1105250e-4811-46b2-b3a1-f25cb9af68a2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Template and compating with select option value

2017-10-29 Thread Andréas Kühne
Hi,

I am not really sure what you are trying to accomplish. What you are
writing doesn't make sense.

I think you should check how to write the paginate by properties. You can
find some information here:
https://docs.djangoproject.com/en/1.11/topics/pagination/
https://simpleisbetterthancomplex.com/tutorial/2016/08/03/how-to-paginate-with-django.html

How you are using the paginate by property doesn't seem to make sense or I
don't understand what you are trying to accomplish :-)

Best regards,

Andréas

2017-10-28 19:04 GMT+02:00 Naaim Iss :

> Hello everyone.
> I hace a ListView-based class with attribute `paginate_by = 12`.
> There is in HTML-template a select element with seveeral options, for
> pagination of course. Options come to the page from context. Loks like this:
> `
> 
> {% for item in per_page_options %}
>  {% if request.GET.results_per_page == item or paginate_by == item
> %}
> selected="selected" {% endif %}
> >{{ item }}
> 
> {% endfor %}
> 
> `
>
> When i change value of select attribute `paginate_by` changes succesfully
> and on page another option is selected, according to new value of
> `paginate_by'
> But when i move to another page on this template the value 'selection'
> stops working and in "options" the first value becomes "selected".
> Even tried to check how this template reads the "context" from "view", by
> adding this code next on page
> `
> {% if request.GET.results_per_page == paginate_by %}
> {{ paginate_by }} - {{ request.GET.results_per_page }}
> {% endif %}
> `
> And after changing the page I can see this new string. Like 3 - 3 or 9 -
> 9, etc.
>
> Looks like some bug. But never saw it before.
> Any ideas?
>
> Thanks anyway.
>
> --
> 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/bb7eeb52-8a29-474a-9607-3cc9f108b1dd%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/CAK4qSCdhao_-SNO3B5s51KxhAwrnvWk9ke-qWKBpDHBKpW9d%3DA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.