Re: Channels: rejecting web socket connections with a custom close code

2018-10-06 Thread Andrew Godwin
Hi Matt,

This is because the two ways of closing are different - closing before the
socket is open sends a HTTP error code (what browsers report for this is
different in terms of websocket errors), whereas closing once it is open
allows a websocket error to be used.

This is referenced in the spec at
https://asgi.readthedocs.io/en/latest/specs/www.html#websocket but somewhat
obliquely; I’ll try to make it a bit clearer.

Andrew

On Wed, 3 Oct 2018 at 13:23, Matt F  wrote:

> Hello all,
>
> I have a question about the process of accepting/rejecting web socket
> connections in Channels consumers (v2.1.3).  I have found that if I have
> code like this:
>
> class MyConsumer(JsonWebsocketConsumer):
> def connect(self):
> if authenticated:
> self.accept()
> else:
> self.close(4001)
>
>
> then when rejecting a connection the close code always comes through on
> the client side as 1006 (abnormal closure) instead of 4001.  There is a
> stack overflow post about the same issue that led me to an answer that
> solves this:
> https://stackoverflow.com/questions/50009440/django-channels-2-0-websocketbridge-js-403-when-self-codecode-1007
>
> And a code snippet that works correctly is as follows:
>
> class MyConsumer(JsonWebsocketConsumer):
> def connect(self):
> self.accept()
> if not authenticated:
> self.close(4001)
>
>
> The Channels documentation is ambiguous as to which of these is correct.
> Now I think I know the answer as the first way breaks and the second way
> works, but I wanted to check with someone more knowledgeable that this way
> of doing things is by design and not just working by accident.  It feels a
> bit wrong to accept a connection and then immediately close it, but I
> understand if you have to do it this way, to get the custom close code
> returned perhaps you have to have an open connection in the first place.
> Can someone please confirm?
>
> Many thanks!
> Matt
>
> --
> 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/6a4a797c-e590-4f4d-a718-074a3cf704bc%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/CAFwN1urect58FqfPUJExwbWd%2BpyWTjU4gLwNdEq9Sm0d1Lv75w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


While registering the user with django form, it gives "UNIQUE constraint failed: auth_user.username" error

2018-10-06 Thread Jaydeep Borkar
When I try to register a user using Django form, it gives me "UNIQUE 
constraint failed: auth_user.username". When I tried registering the first 
user, it worked, but I couldn't see that entry in my database. When I tried 
registering the second user, it's giving me this error. Please, help me 
through this. I have spent a considerable amount of time on this and I'm 
stuck. 

This is my code: 

forms.py 
from django import forms
from django.contrib.auth.models import User
from volunteer.models import UserProfileInfo

class UserForm(forms.ModelForm):

class Meta():
model = User
fields = ('email','first_name','last_name')




views.py 
from django.shortcuts import render
from volunteer.forms import UserForm

 

def register(request):

registered = False

if request.method =="POST" :
user_form = UserForm(data=request.POST)

if user_form.is_valid():

user = user_form.save()
user.save()

registered = True

else:
print(user_form.errors)

else:
user_form = UserForm()

return render(request, 'volunteer/volunteer.html',
 {'user_form':user_form,
  'registered':registered})

 
  






models.py 
from django.db import models
from django.contrib.auth.models import User

class UserProfileInfo(models.Model):

user=models.OneToOneField(User)

def __str__(self):
return self.user.first_name
return self.user.last_name
return self.user.email







urls.py
from django.conf.urls import url

from . import views

app_name = 'volunteer'

urlpatterns = [

 url(r'^', views.register, name='register'),
]



admin.py
from django.contrib import admin
from volunteer.models import UserProfileInfo

# Register your models here.
admin.site.register(UserProfileInfo)



volunteer.html file which has the user form




 
 


 
https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css";>
https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js";>
https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js";>
 https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js";>
 
  
 
  

 
{% if registered %}
   Thanks!
{% else %}
  Register


 
{% csrf_token %}
{{ user_form.as_p }}
 

 {% endif %}

  

 
 


 



I feel there's some problem in views.py or models.py, or volunteer.html. or 
maybe something else. Please, guide me through this. 
Thanks in advance. 

-- 
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/e74c61d0-db1f-48d3-ac35-f438752275ab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Channels: rejecting web socket connections with a custom close code

2018-10-06 Thread replyveer25
hello someone help me i am getting django 404 error ..how fix it ...please 
help me i am so frustrated


On Wednesday, 3 October 2018 04:23:30 UTC-7, Matt F wrote:
>
> Hello all,
>
> I have a question about the process of accepting/rejecting web socket 
> connections in Channels consumers (v2.1.3).  I have found that if I have 
> code like this:
>
> class MyConsumer(JsonWebsocketConsumer):
> def connect(self):
> if authenticated:
> self.accept()
> else:
> self.close(4001)
>
>
> then when rejecting a connection the close code always comes through on 
> the client side as 1006 (abnormal closure) instead of 4001.  There is a 
> stack overflow post about the same issue that led me to an answer that 
> solves this: 
> https://stackoverflow.com/questions/50009440/django-channels-2-0-websocketbridge-js-403-when-self-codecode-1007
>
> And a code snippet that works correctly is as follows:
>
> class MyConsumer(JsonWebsocketConsumer):
> def connect(self):
> self.accept()
> if not authenticated:
> self.close(4001)
>
>
> The Channels documentation is ambiguous as to which of these is correct.  
> Now I think I know the answer as the first way breaks and the second way 
> works, but I wanted to check with someone more knowledgeable that this way 
> of doing things is by design and not just working by accident.  It feels a 
> bit wrong to accept a connection and then immediately close it, but I 
> understand if you have to do it this way, to get the custom close code 
> returned perhaps you have to have an open connection in the first place.  
> Can someone please confirm?
>
> Many thanks!
> Matt
>
>

-- 
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/0cb3c59f-21c6-4e3c-b7f2-2242e59e4e58%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


geodjango raster field get pixel value

2018-10-06 Thread Majid Hojati
Hi,
Is there any function to get raster value under a point using geodjango?or 
we must perform a raw query?

-- 
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/63334e6f-2ac5-434f-8041-6e4bea64e33c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: geodjango raster field get pixel value

2018-10-06 Thread Pradeep Singh
i don't know,  i hava a problem can you solve this .

On Sat, 6 Oct 2018 at 10:09, Majid Hojati  wrote:

> [image: Boxbe]  This message is eligible
> for Automatic Cleanup! (asd5...@gmail.com) Add cleanup rule
> 
> | More info
> 
> Hi,
> Is there any function to get raster value under a point using geodjango?or
> we must perform a raw query?
>
> --
> 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/63334e6f-2ac5-434f-8041-6e4bea64e33c%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/CANwgZcZkmLNuQxzZhSAp7CVKewWXG%2BCEeZgj9vgtJ3i4PE_05g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: geodjango raster field get pixel value

2018-10-06 Thread Pradeep Singh
when i  sendind request  always m getting django 404 error can you help me
..nd please tell me how to fix it

On Sat, 6 Oct 2018 at 10:42, Pradeep Singh  wrote:

> i don't know,  i hava a problem can you solve this .
>
> On Sat, 6 Oct 2018 at 10:09, Majid Hojati  wrote:
>
>> [image: Boxbe]  This message is eligible
>> for Automatic Cleanup! (asd5...@gmail.com) Add cleanup rule
>> 
>> | More info
>> 
>> Hi,
>> Is there any function to get raster value under a point using
>> geodjango?or we must perform a raw query?
>>
>> --
>> 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/63334e6f-2ac5-434f-8041-6e4bea64e33c%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/CANwgZcak%3DMDBvzPAiH%3DUNYmbuhE0jQkO88gD0OHShT2ErYzmxA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


I put 3 more fields on database models

2018-10-06 Thread Bleron Uka
Hi, 
My database has data there and i add 3 more inputs and i am having this 
error ?!

-- 
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/9d3c91cd-7568-417e-98eb-f38325a38120%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: I put 3 more fields on database models

2018-10-06 Thread Manjunath
Seems like you have not performed migrations after adding the new fields.

execute these commands & then run your server.

python manage.py makemigrations

python manage.py migrate

 


On Sunday, October 7, 2018 at 3:33:54 AM UTC+5:30, Bleron Uka wrote:
>
> Hi, 
> My database has data there and i add 3 more inputs and i am having this 
> error ?!
>

-- 
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/69a9ed3d-d083-49b6-bad4-80ffe7a3bc77%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: I put 3 more fields on database models

2018-10-06 Thread daniel main
Hello. Try and make the migrations then migrate. I hope that helps

On Oct 7, 2018 01:03, "Bleron Uka"  wrote:

Hi,
My database has data there and i add 3 more inputs and i am having this
error ?!

-- 
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/9d3c91cd-7568-417e-98eb-f38325a38120%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/CAEEZZ8KtoanDkZW8HTovhG1k_cWSz_VK2%3Djzhn2i9ePkp9emgA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


RE: I put 3 more fields on database models

2018-10-06 Thread Deepak Kumar jha
After adding fields in model you have to do 
1:python manage.py makemigrations (app_name)
2: Python manage.py migrate

Sent from my Windows 10 phone

From: Bleron Uka
Sent: 07 October 2018 03:33 AM
To: Django users
Subject: I put 3 more fields on database models

Hi, 
My database has data there and i add 3 more inputs and i am having this error ?!
-- 
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/9d3c91cd-7568-417e-98eb-f38325a38120%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/5bb9a4c9.1c69fb81.42d94.e9b4%40mx.google.com.
For more options, visit https://groups.google.com/d/optout.