Protect Django media files per user basis and also under NGINX

2021-04-19 Thread Tal Bar-Or


Hello,

i have a project that create qrcode per user one to one relation, i 
discover that this media qr iame can be access if url is known .

Can somone please help me with best practice to Protect Django media files 
per user basis and also under NGINX for later production

Please advice

Thanks

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/cac7d1c4-f2df-4b94-9fa5-01260634afbbn%40googlegroups.com.


Using Signals and method in models to automate key and qrcode>> help

2021-04-17 Thread Tal Bar-Or


Hello ,

i have a simple model that create additional one to one relation to User a 
profile like table with tables of pytop code and qrcode associated per user.

I had success to create the pytop code ,but the qr code i have difficulty 
to achieve it since i need to get,

The current users created and the pyotp code, on evry user creation i have 
signals receivers that create the additional profile associated tables , 
but i need your advice ,on methods attached to the model that will create 
automatically the request tables , what is the best practice to achieve 
such task.

Please advice

Thanks

*The profile model*

from django.db import models
from django.contrib.auth.models import User
import pyotp
import qrcode


# Create your models here.



def otp_google_auth(code,usr):
print('details: ',code,usr)

googleauth = pyotp.totp.TOTP(code).provisioning_uri(name=str(usr) + 
'@google.com', issuer_name='Secure Dalet')
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
qr.add_data(googleauth)
qr.make(fit=True)

img = qr.make_image(fill_color="black", back_color="white")

google_qr = img 

class Profile(models.Model):

user = models.OneToOneField(User, on_delete=models.CASCADE, blank=True, 
null=True)

#qr_creation = otp_google_auth(secret, user)
otp_code = models.CharField(max_length=200, default=token_creation)
user_qr =  models.ImageField(upload_to='images/', default= None)
last_name = models.CharField(max_length=200, null=True, blank=True)
phone = models.CharField(max_length=200, null=True, blank=True)

def __str__(self):
return str(self.user)

def token_creation(self):

secret = pyotp.random_base32()
self.otp_code.save(secret, save=False)
super().save()

*The  signals for profile table*

from django.db.models.signals import post_save
from django.dispatch import receiver

from django.contrib.auth.models import User
from .models import Profile

@receiver(post_save, sender=User)
def create_profile(sender, instance, created, **kwargs):

if created:
Profile.objects.create(user=instance)
print('Profile created!')

#post_save.connect(create_profile, sender=User)

@receiver(post_save, sender=User)
def update_profile(sender, instance, created, **kwargs):

if created == False:
instance.profile.save()
print('Profile updated!')




-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/94e3236b-3633-4937-89bd-bf38adade13dn%40googlegroups.com.


Advice on self service password reset?

2021-02-26 Thread Tal Bar-Or
 Hello ,
I would like to write self service password service for our organization , 
the identity source is our active directory.
To accomplish this task i choose to use ldap3 library , reset password 
procedure would be simple template with enter your mail , backend will look 
for email user attribute existence, if it is will send token temporary for 
x amount of time url to user email, that would let him eventually reset 
password template .
I know that Django have internal mechanism for user s reset password such 
as 
*from django.contrib.auth.tokens import PasswordResetTokenGenerator*
But I guess this is not relevant for my use case , my question/advice I 
would like to get is.
How to accomplish such task what library ,mechanism and logic should i use ?
Please advice
Thanks

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5b81ac5e-b649-4e3f-98fb-21c3164640dan%40googlegroups.com.


Raw View class without form and model

2021-02-17 Thread Tal Bar-Or


Hello ,

I would like to write Raw view model for current scenario,

i started writing portal for self service AD change password , the view for 
the change password is no need any model ,since it should be is using 
background ldap3 library , in addition i would like in a POST method to 
read the HTML name tag for current password and new password without need 
of form

i started to build the view class , but seems i am missing something, if 
someone can assist me will be appreciated.

Thanks

*view class*

class ChangeUserPassword(View):
info_sended = False
template_name = "changepassword.html"
AUTH_SERVER = config('AUTH_SERVER')
BASEDN = config('BASEDN')
#form_class = UserChangePasswordForm
#success_url = reverse_lazy('loader_success')

def get(self, request):
current_user = request.user
context = {'form' : current_user}
return render(request, self.template_name, context)

def post(self, request):
PassForm = ""
#form = PassForm()
if request.method == 'POST':
form = PassForm(request.POST)

if form.is_valid():
current_user = request.user
print(current_user)

*HTML form*



  
  
  


{% csrf_token %}


  
  


Current Password 


  

  

  

  
  



  
  Don't match password'


  
  
  

  
  


Password


  

  

  

  


-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/cd394b13-c20a-4ca8-ada9-0f779b744019n%40googlegroups.com.


Re: How to add css class and attribute to username,password

2021-02-14 Thread Tal Bar-Or
Thank you very much all for the helpful advice
Thanks again

Le dim. 14 févr. 2021 à 21:46, Omkar Parab  a écrit :

> crispy-forms will give you bootstrap design. If you want to apply your own
> css then install "django-widget-tweaks".
>
> On Mon, Feb 15, 2021, 1:10 AM Omkar Parab  wrote:
>
>> Install django-widget-tweaks package.
>>
>> On Mon, Feb 8, 2021, 2:11 AM Tal Bar-Or  wrote:
>>
>>>
>>> Hello ,
>>>
>>> I writing project which the user login with my own customized HTML page
>>> (boosstrap)
>>>
>>> i can manually add the form.username and form.password , but seems they
>>> don't get the attribute from my forms.py , dode is added below , please
>>> advise
>>>
>>> Thanks
>>>
>>>
>>> urls.py
>>> from django.urls import path
>>> from django.contrib.auth import views as auth_views from .views import *
>>> urlpatterns = [
>>> path('login/', auth_views.LoginView.as_view(), name = 'login'),
>>>  path('signup/', SignUpView.as_view(), name='signup'), ]
>>>
>>>
>>> views.py
>>> from django.contrib.auth.forms import UserCreationForm
>>> from django.contrib.auth.views import LoginView
>>> from django.urls import reverse_lazy from django.views import generic
>>> from .forms import * class UsersLoginView(LoginView):
>>> template_name = 'login.html' success_url = 'blog-home'
>>> success_message = 'Welcome to your profile'
>>> form_class = UserLoginForm
>>>
>>> forms.py
>>> from django import forms from django.forms import ModelForm
>>> from .models import User class UserLoginForm(forms.ModelForm):
>>> username = forms.CharField(widget=forms.TextInput(attrs={'class': 
>>> 'form-control', 'type':'email', 'name':'Username', 
>>> 'placeholder':'Username'}))
>>> password = forms.CharField(widget=forms.PasswordInput(attrs={'class': 
>>> 'form-control', 'type': 'password', 'name': 'password', 
>>> 'placeholder':'Password'}))
>>>
>>>
>>> --
>>> 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 view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/f757c3c4-d8bf-4cc0-89a2-48638130b59an%40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/f757c3c4-d8bf-4cc0-89a2-48638130b59an%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/I0QLsyReqZU/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAJY8mfwdUK8eh%2BZynZ2fX4oH6-34g6PEPa9TqSGCpbvhmGcD0A%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAJY8mfwdUK8eh%2BZynZ2fX4oH6-34g6PEPa9TqSGCpbvhmGcD0A%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAM0M%3Dj2DpXQyZmnkWg0h6UjHusZp9_gn0Cz4QW8jO96RaK%3DZbA%40mail.gmail.com.


How can I use a Sync HTTP Consumer in Django Channels?

2021-02-08 Thread Tal


I'm using Channels v2. I want to integrate long-polling into my project.

The only consumer I see in the documentation for http long polling is the 
AsyncHttpConsumer 

.

The code I need to run in my handle function is not asynchronous. It 
connects to another device on the network using a library that is not 
asynchronous. From what I understand, this will cause the event loop to 
block, which is bad. Client requests will be handled one at a time.

Can I run my handler synchronously, in a thread somehow?

I asked the same question 
here: https://stackoverflow.com/q/66055657/6423456, but so far got no 
responses.

I quickly wrote a subclass of SyncConsumer that works, but:


   1. I can't imagine that everyone is doing this - there must be an easier 
   way
   2. The disconnect() method is not called until after the handle() method 
   is done running, so from what I can tell, there's no way to interrupt the 
   handle method early (unless the handle method kicks off its own thread or 
   something)

I posted the code for the subclass of SyncConsumer as an answer to my 
stackoverflow question, but I'm hoping there's a better, easier way to do 
this.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6f40e058-b330-40bd-980b-4569b2975375n%40googlegroups.com.


How to add css class and attribute to username,password

2021-02-07 Thread Tal Bar-Or


Hello ,

I writing project which the user login with my own customized HTML page 
(boosstrap)

i can manually add the form.username and form.password , but seems they 
don't get the attribute from my forms.py , dode is added below , please 
advise

Thanks


urls.py
from django.urls import path 
from django.contrib.auth import views as auth_views from .views import * 
urlpatterns = [ 
path('login/', auth_views.LoginView.as_view(), name = 'login'), 
 path('signup/', SignUpView.as_view(), name='signup'), ] 


views.py
from django.contrib.auth.forms import UserCreationForm 
from django.contrib.auth.views import LoginView 
from django.urls import reverse_lazy from django.views import generic 
from .forms import * class UsersLoginView(LoginView): 
template_name = 'login.html' success_url = 'blog-home' 
success_message = 'Welcome to your profile' 
form_class = UserLoginForm 

forms.py
from django import forms from django.forms import ModelForm 
from .models import User class UserLoginForm(forms.ModelForm): 
username = forms.CharField(widget=forms.TextInput(attrs={'class': 
'form-control', 'type':'email', 'name':'Username', 'placeholder':'Username'})) 
password = forms.CharField(widget=forms.PasswordInput(attrs={'class': 
'form-control', 'type': 'password', 'name': 'password', 
'placeholder':'Password'})) 

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f757c3c4-d8bf-4cc0-89a2-48638130b59an%40googlegroups.com.


Can we modify SQLCompiler to get a read-only model that selects from a subquery

2020-03-08 Thread Tal Perry
Hi,
I'll start with some context so the question makes more sense. 
We run a multi-tenant SaaS where we use database multi-tenancy (one db per 
tenant).
Part of offering is extensive and rather complex reporting, which is hard 
to do in the django ORM in a performant manner.

The ability to use the orms filter abilities is important to us, and so 
we've been defining views and wrapping them in unmanaged models.
We aren't thrilled about this for multiple reasons, but primarily because 
migrations are no fun when you do database multi tenancy. 

This use case being reporting, we'd be fine with a "Read Only Model", where 
in the models Meta classs we'd specify some SQL (much like raw) and the 
SQLCompiler would use that SQL to select from and filter (much like a view).

Is this possible ? Does anyone have thoughts on how to get started ? 
 Thanks

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d4c56b1d-58fc-4bd4-a3b7-49853e531186%40googlegroups.com.


How to iterate over inlineformset_factory fields only?

2020-02-02 Thread Tal Bar-Or


Hello,

I am trying to figure out how to access *inlineformset_factory* ,i set to 
represent my ForeignKey fields to present them in html i would like to 
iterate over those inlineformset_factory only in html, but i can't figure 
out how to achieve it, i can get display only field manually like 
{{form.task_description}} , but no luck to iterate over all ForeignKey 
fields , i would like to dispaly each object in collapse bs4
if someone could help me point to achieve it.

Please advice

Thanks


my view.py related class goes as follows
class TaskIdUpdateView(UpdateView):
taskidformset = inlineformset_factory(MainTask,ChildTask, fields=(
'task_description','task_info','task_complete',
'sub_task','task_precent_complete','task_due_date','task_assign'))
model = MainTask
template_name = "taskid_update.html"
form_class = TaskUpdateForm


my formd.py related class

class TaskUpdateForm(ModelForm):

TASK_STATUS_CHOICES = [
('ST', 'STARTED'),
('NS', 'NOT STARTED'),
('IP', 'IN PROGRESS'),
('PA', 'PAUSED'),
('CO', 'COMPLETED'),
]
INPUTֹTIMEֹFORMATS = ['%Y-%m-%d',  # '2006-10-25'
'%m/%d/%Y',
'%Y/%m/%d',   # '10/25/2006'
'%Y/%m/%d %H:%M',
'%m/%d/%y',
'%Y-%m-%d %H:%M:%S']   # '10/25/06'

#Main Task objects
task_title = forms.CharField(required=False, widget=forms.TextInput(
attrs={'class':'form-control','placeholder':'Task Title'}))
global_task_info = forms.CharField(required=True, widget=forms.Textarea(
attrs={'class':'form-control','placeholder':'Task Description'}))
due_date = forms.DateTimeField(required=False, input_formats=
INPUTֹTIMEֹFORMATS, widget=forms.DateTimeInput(attrs={
'class': 'form-control',
'id': 'picker'
}))
global_task_assign = forms.ModelChoiceField(queryset=
 UserProfile.objects.all(), widget=forms.Select(attrs={'class':
'form-control'} ))
task_status = forms.ChoiceField(label='', choices=TASK_STATUS_CHOICES, 
widget=forms.Select(attrs={'class':'form-control'}))
complete = forms.BooleanField( required=False, widget=
forms.CheckboxInput(attrs={'type':'checkbox', 'class':'custom-control-input'
, 'id':'switchcomplete'}))
overall_precent_complete = forms.IntegerField(widget=(forms.NumberInput(
attrs={'type':'range', 'min':'0', 'max':'100', 'value':'50', 'class':
'range-slider__range', 'id':'PreRange'})))
task_location = forms.CharField(widget=forms.TextInput(attrs={'class':
'form-control'}))

#Child Tasks objects
task_description = forms.CharField(max_length=200, widget=
forms.TextInput(attrs={'class':'form-control','placeholder':
'Sub Task Description'}))
task_info = forms.CharField(max_length=500, widget=forms.Textarea(attrs=
{'class':'form-control','placeholder':'Sub Task Description'}))
task_complete = forms.BooleanField( required=False, widget=
forms.CheckboxInput(attrs={'type':'checkbox', 'class':'custom-control-input'
, 'id':'switchcomplete'}))
sub_task = forms.CharField(max_length=500, widget=forms.Textarea(attrs={
'class':'form-control','placeholder':'Sub Task Description'}))
task_precent_complete = forms.IntegerField(widget=(forms.NumberInput(
attrs={'type':'range', 'min':'1', 'max':'100', 'value':'50', 'class':
'slider', 'id':'myRange'})))
task_due_date = forms.DateTimeField(input_formats=INPUTֹTIMEֹFORMATS, 
widget=forms.DateTimeInput(attrs={
'class': 'form-control',
'id': 'picker'
}))
task_assign = forms.ModelChoiceField(queryset=
 UserProfile.objects.all(), widget=forms.Select(attrs={'class':
'form-control'} ))
  
class  Meta:

model = MainTask
fields = ['task_title',
'global_task_info',
'due_date',
'global_task_assign',
'task_status',
'complete',
'overall_precent_complete',
'task_location',
'global_task_assign',
'task_status',]

taskidformset = inlineformset_factory(MainTask, ChildTask, fields=(
'task_description','task_info','task_complete',
'sub_task','task_precent_complete','task_due_date','task_assign'
))



-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/89d1f875-07f0-41ae-bc6e-6b81689a89e5%40googlegroups.com.


What's the best practice for securing static and media files from unauthenticated users?

2019-07-23 Thread Tal
I have a Django project, where, for the most part, users need to be logged 
in to see or do anything.

If an unauthenticated user guesses a page name in my project, they would 
get redirected to the login page, with an error message, as they should.

The project's static and media files on the other hand had no protection. 
If someone guesses their names (and URL), authenticated or not, they would 
be allowed to download them.

To fix this, I configured Nginx to mark all static and media files as 
Internal, and I wrote middleware that sends my Nginx server the 
X-Accel-Redirect header if users are authenticated. The code is here. 
 
Functionally, 
this seems to work great - at least in testing.

Unfortunately, when looking at my Firefox development tools, Django's Admin 
Logged-In page takes about 1 second to load without this middleware 
enabled, and about 3.5 seconds to load with this middleware enabled.

Am I doing something inefficiently in my middleware? Or is the idea of 
having every single request for every static resource be authorized by 
django, rather than quickly returned by Nginx, inherently inefficient?

What's the best practice?

   - Is it to leave static files unprotected (css and js files don't 
   normally have anything confidential), while securing /media files with 
   X-Accel-Redirect?
   - Is it to have everything unprotected, but obfuscate the filenames of 
   the resources to make them super difficult to guess, but quick to be 
   returned by Nginx?
   - Is there no best practice? Is it done on a case-by-case basis 
   depending on the level of confidentiality of the static/media files you are 
   dealing with?

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7ee0735e-1266-4f51-aff6-a2d60cbd8a41%40googlegroups.com.


Re: SQLite 3.8.3 or later is required (found 3.7.17).

2019-07-19 Thread Tal
Or, if you prefer, use a slightly older version of Django that doesn't 
require an sqlite library that's newer than your OS has.

Either that, or if you plan on using a database other than sqlite in 
production, once you modify your settings.py's DATABASES variable to use 
something other than sqlite, you won't have this problem anymore.

On Friday, July 19, 2019 at 2:08:50 PM UTC-6, Tal wrote:
>
> This is a known problem 
> <https://www.google.com/url?q=https%3A%2F%2Fcode.djangoproject.com%2Fticket%2F30313&sa=D&sntz=1&usg=AFQjCNFEZ2GRHkL_bqyMdSDy3JG3hcC3rQ>
>  - 
> at least on CentOS 7. Not sure what OS you're running on AWS - I don't have 
> much experience with AWS. I literally just ran into this on my CentOS 7. I 
> posted a fix for CentOS 7. Maybe it'll help you.
>
>
> On Friday, July 19, 2019 at 1:22:20 PM UTC-6, Jani Tiainen wrote:
>>
>> Hi.
>>
>> Error is simple. Python is using too old version of sqlite. There are few 
>> options to fix that depending what os your system runs on.
>>
>> Though sqlite is not very suitable for production so you may want to use 
>> something better like Postgres.
>>
>>
>> pe 19. heinäk. 2019 klo 22.14 anchal agarwal  
>> kirjoitti:
>>
>>> This is my whole Traceback
>>> Traceback (most recent call last):
>>>   File "manage.py", line 15, in 
>>> execute_from_command_line(sys.argv)
>>>   File 
>>> "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py",
>>>  
>>> line 381, in execute_from_command_line
>>> utility.execute()
>>>   File 
>>> "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py",
>>>  
>>> line 357, in execute
>>> django.setup()
>>>   File "/usr/local/lib/python3.7/site-packages/django/__init__.py", line 
>>> 24, in setup
>>> apps.populate(settings.INSTALLED_APPS)
>>>   File "/usr/local/lib/python3.7/site-packages/django/apps/registry.py", 
>>> line 114, in populate
>>> app_config.import_models()
>>>   File "/usr/local/lib/python3.7/site-packages/django/apps/config.py", 
>>> line 211, in import_models
>>> self.models_module = import_module(models_module_name)
>>>   File "/usr/lib64/python3.7/importlib/__init__.py", line 127, in 
>>> import_module
>>> return _bootstrap._gcd_import(name[level:], package, level)
>>>   File "", line 1006, in _gcd_import
>>>   File "", line 983, in _find_and_load
>>>   File "", line 967, in 
>>> _find_and_load_unlocked
>>>   File "", line 677, in _load_unlocked
>>>   File "", line 728, in exec_module
>>>   File "", line 219, in 
>>> _call_with_frames_removed
>>>   File "/home/ec2-user/wavybeatz/music/models.py", line 4, in 
>>> class Album(models.Model):
>>>   File 
>>> "/usr/local/lib/python3.7/site-packages/django/db/models/base.py", line 
>>> 117, in __new__
>>> new_class.add_to_class('_meta', Options(meta, app_label))
>>>   File 
>>> "/usr/local/lib/python3.7/site-packages/django/db/models/base.py", line 
>>> 321, in add_to_class
>>> value.contribute_to_class(cls, name)
>>>   File 
>>> "/usr/local/lib/python3.7/site-packages/django/db/models/options.py", line 
>>> 204, in contribute_to_class
>>> self.db_table = truncate_name(self.db_table, 
>>> connection.ops.max_name_length())
>>>   File "/usr/local/lib/python3.7/site-packages/django/db/__init__.py", 
>>> line 28, in __getattr__
>>> return getattr(connections[DEFAULT_DB_ALIAS], item)
>>>   File "/usr/local/lib/python3.7/site-packages/django/db/utils.py", line 
>>> 201, in __getitem__
>>> backend = load_backend(db['ENGINE'])
>>>   File "/usr/local/lib/python3.7/site-packages/django/db/utils.py", line 
>>> 110, in load_backend
>>> return import_module('%s.base' % backend_name)
>>>   File "/usr/lib64/python3.7/importlib/__init__.py", line 127, in 
>>> import_module
>>> return _bootstrap._gcd_import(name[level:], package, level)
>>>   File "", line 1006, in _gcd_import
>>>   File "", line 983, in _find_and_load
>>>   File "", line 967, in 
>>> _find_and_load_unlocked
>&

Re: Why am I getting multiple django error report emails for every exception?

2019-07-19 Thread Tal
After a bit of digging, it turns out that if I disable the django-channels 
app that I'm using, I only get the one email with the exception that was 
thrown.
Even if I don't disable the django-channels app, and run it with daphne (as 
I would in production), rather than using the django channels ASGI 
development server, it works fine, and I only get one email when an 
exception is thrown.

On Friday, July 19, 2019 at 10:23:49 AM UTC-6, Tal wrote:
>
> I setup my django 2.2.3 project to use gmail to send emails out.
>
> I also have it configured to send me emails about any exceptions that 
> occur.
>
> To test it, I made a view with:
>
> float('a')
>
> It works, but I'm getting 2 emails in my Gmail inbox every time I hit that 
> view:
>
> [image: Screen Shot 2019-07-19 at 10.10.53 AM.png]
>
> The first email above seems to be related to the fact that after django 
> hit my float('a') line, an HTTP 500 exception was thrown. One of the lines 
> in it reads "Request data not supplied", if that helps.
>
> The second email above actually has the traceback from the float('a') 
> exception. It does have request data supplied (GET parameters, POST 
> parameters, COOKIES, FILES, etc).
>
> Is this normal? Is the email about the HTTP 500 exception ever useful? It 
> seems like it would always be accompanied by another email with more detail 
> about why the HTTP 500 error occurred, making it pretty useless. If so, is 
> there a way to disable it? Or am I doing something wrong?
>
> PS. I started a different topic about why the first email has characters 
> like [35;1m in it, which seems unrelated.
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4d320bc1-38c8-4180-aa9f-4bf5689d83e6%40googlegroups.com.


Re: SQLite 3.8.3 or later is required (found 3.7.17).

2019-07-19 Thread Tal
This is a known problem 

 - 
at least on CentOS 7. Not sure what OS you're running on AWS - I don't have 
much experience with AWS. I literally just ran into this on my CentOS 7. I 
posted a fix for CentOS 7. Maybe it'll help you.


On Friday, July 19, 2019 at 1:22:20 PM UTC-6, Jani Tiainen wrote:
>
> Hi.
>
> Error is simple. Python is using too old version of sqlite. There are few 
> options to fix that depending what os your system runs on.
>
> Though sqlite is not very suitable for production so you may want to use 
> something better like Postgres.
>
>
> pe 19. heinäk. 2019 klo 22.14 anchal agarwal  > kirjoitti:
>
>> This is my whole Traceback
>> Traceback (most recent call last):
>>   File "manage.py", line 15, in 
>> execute_from_command_line(sys.argv)
>>   File 
>> "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", 
>> line 381, in execute_from_command_line
>> utility.execute()
>>   File 
>> "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", 
>> line 357, in execute
>> django.setup()
>>   File "/usr/local/lib/python3.7/site-packages/django/__init__.py", line 
>> 24, in setup
>> apps.populate(settings.INSTALLED_APPS)
>>   File "/usr/local/lib/python3.7/site-packages/django/apps/registry.py", 
>> line 114, in populate
>> app_config.import_models()
>>   File "/usr/local/lib/python3.7/site-packages/django/apps/config.py", 
>> line 211, in import_models
>> self.models_module = import_module(models_module_name)
>>   File "/usr/lib64/python3.7/importlib/__init__.py", line 127, in 
>> import_module
>> return _bootstrap._gcd_import(name[level:], package, level)
>>   File "", line 1006, in _gcd_import
>>   File "", line 983, in _find_and_load
>>   File "", line 967, in 
>> _find_and_load_unlocked
>>   File "", line 677, in _load_unlocked
>>   File "", line 728, in exec_module
>>   File "", line 219, in 
>> _call_with_frames_removed
>>   File "/home/ec2-user/wavybeatz/music/models.py", line 4, in 
>> class Album(models.Model):
>>   File "/usr/local/lib/python3.7/site-packages/django/db/models/base.py", 
>> line 117, in __new__
>> new_class.add_to_class('_meta', Options(meta, app_label))
>>   File "/usr/local/lib/python3.7/site-packages/django/db/models/base.py", 
>> line 321, in add_to_class
>> value.contribute_to_class(cls, name)
>>   File 
>> "/usr/local/lib/python3.7/site-packages/django/db/models/options.py", line 
>> 204, in contribute_to_class
>> self.db_table = truncate_name(self.db_table, 
>> connection.ops.max_name_length())
>>   File "/usr/local/lib/python3.7/site-packages/django/db/__init__.py", 
>> line 28, in __getattr__
>> return getattr(connections[DEFAULT_DB_ALIAS], item)
>>   File "/usr/local/lib/python3.7/site-packages/django/db/utils.py", line 
>> 201, in __getitem__
>> backend = load_backend(db['ENGINE'])
>>   File "/usr/local/lib/python3.7/site-packages/django/db/utils.py", line 
>> 110, in load_backend
>> return import_module('%s.base' % backend_name)
>>   File "/usr/lib64/python3.7/importlib/__init__.py", line 127, in 
>> import_module
>> return _bootstrap._gcd_import(name[level:], package, level)
>>   File "", line 1006, in _gcd_import
>>   File "", line 983, in _find_and_load
>>   File "", line 967, in 
>> _find_and_load_unlocked
>>   File "", line 677, in _load_unlocked
>>   File "", line 728, in exec_module
>>   File "", line 219, in 
>> _call_with_frames_removed
>>   File 
>> "/usr/local/lib/python3.7/site-packages/django/db/backends/sqlite3/base.py", 
>> line 66, in 
>> check_sqlite_version()
>>   File 
>> "/usr/local/lib/python3.7/site-packages/django/db/backends/sqlite3/base.py", 
>> line 63, in check_sqlite_version
>> raise ImproperlyConfigured('SQLite 3.8.3 or later is required (found 
>> %s).' % Database.sqlite_version)
>> django.core.exceptions.ImproperlyConfigured: SQLite 3.8.3 or later is 
>> required (found 3.7.17).
>>
>> On Sat, Jul 20, 2019 at 12:29 AM anchal agarwal > > wrote:
>>
>>> I used default sqlite as my Database
>>> DATABASES = {
>>> 'default': {
>>> 'ENGINE': 'django.db.backends.sqlite3',
>>> 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
>>> }
>>> }
>>> My python version is python3 and Django version is 2.1.5
>>>
>>> On Fri, Jul 19, 2019 at 7:06 PM Desh Deepak >> > wrote:
>>>
 Hi, show me your database connection, also tell me python and Django 
 version.


 On Fri, 19 Jul 2019, 18:06 anchal agarwal, >>> > wrote:

> Hello Django users,
> i am trying to deploy my django on AWS 
> I am following this 
> https://medium.com/@charlesthk/deploy-nginx-django-uwsgi-on-aws-ec2-amazon-linux-517a683163c6
> Everything was going right but when i run python manage.py migrate , 
> it's giving me this error
> django.core.exceptions.ImproperlyConfigured: SQLite 3.8.3 or later

Re: Why do my django email error reports have weird characters in the subject?

2019-07-19 Thread Tal
Ended up being related to the other problem I was having, where I was 
getting 2 emails for every exception, and both problems were caused by 
enabled django-channels.

Disabling django channels, or running django-channels in production with 
daphne, rather than using the channels ASGI development server, everything 
works - I only get one email, and its formatting is fine. The channels 
development server though sends me 2 emails if an exception is thrown, and 
one of the emails has those weird characters.

If anyone knows a way to fix this, let me know. If not, I'll just have to 
ignore it. I guess it doesn't really bother me if it doesn't happen in 
production.


On Friday, July 19, 2019 at 11:31:26 AM UTC-6, Tal wrote:
>
> Is this possibly related to the fact that I have django-channels enabled?
> I'll try disabling it to see if it's related.
>
> On Friday, July 19, 2019 at 9:46:20 AM UTC-6, Tal wrote:
>>
>> I setup my django 2.2.3 project to use gmail to send emails out.
>>
>> I also have it configured to send me emails about any exceptions that 
>> occur.
>>
>> To test it, I made a view with:
>>
>>
>> float('a')
>>
>> It works, but there are weird characters in the subject of the email I 
>> receive, and in the first part of the message. I think those are bash color 
>> code characters.
>>
>> Why am I seeing them? Is this a Django bug? Any way to fix it?
>>
>>
>>
>>
>> [image: Screen Shot 2019-07-19 at 9.38.26 AM.png]
>>
>>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b42fd92c-fb0a-4dc9-97c8-d57b55f7b01d%40googlegroups.com.


Re: Why do my django email error reports have weird characters in the subject?

2019-07-19 Thread Tal
Is this possibly related to the fact that I have django-channels enabled?
I'll try disabling it to see if it's related.

On Friday, July 19, 2019 at 9:46:20 AM UTC-6, Tal wrote:
>
> I setup my django 2.2.3 project to use gmail to send emails out.
>
> I also have it configured to send me emails about any exceptions that 
> occur.
>
> To test it, I made a view with:
>
>
> float('a')
>
> It works, but there are weird characters in the subject of the email I 
> receive, and in the first part of the message. I think those are bash color 
> code characters.
>
> Why am I seeing them? Is this a Django bug? Any way to fix it?
>
>
>
>
> [image: Screen Shot 2019-07-19 at 9.38.26 AM.png]
>
>

-- 
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/f2067717-a6da-486c-a80b-e4c21a0b5b57%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Why am I getting multiple django error report emails for every exception?

2019-07-19 Thread Tal


I setup my django 2.2.3 project to use gmail to send emails out.

I also have it configured to send me emails about any exceptions that occur.

To test it, I made a view with:

float('a')

It works, but I'm getting 2 emails in my Gmail inbox every time I hit that 
view:

[image: Screen Shot 2019-07-19 at 10.10.53 AM.png]

The first email above seems to be related to the fact that after django hit 
my float('a') line, an HTTP 500 exception was thrown. One of the lines in 
it reads "Request data not supplied", if that helps.

The second email above actually has the traceback from the float('a') 
exception. It does have request data supplied (GET parameters, POST 
parameters, COOKIES, FILES, etc).

Is this normal? Is the email about the HTTP 500 exception ever useful? It 
seems like it would always be accompanied by another email with more detail 
about why the HTTP 500 error occurred, making it pretty useless. If so, is 
there a way to disable it? Or am I doing something wrong?

PS. I started a different topic about why the first email has characters 
like [35;1m in it, which seems unrelated.

-- 
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/dca8d75c-4eab-4507-ae23-f92663a252f3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Why do my django email error reports have weird characters in the subject?

2019-07-19 Thread Tal


I setup my django 2.2.3 project to use gmail to send emails out.

I also have it configured to send me emails about any exceptions that occur.

To test it, I made a view with:


float('a')

It works, but there are weird characters in the subject of the email I 
receive, and in the first part of the message. I think those are bash color 
code characters.

Why am I seeing them? Is this a Django bug? Any way to fix it?




[image: Screen Shot 2019-07-19 at 9.38.26 AM.png]

-- 
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/25ab432a-7dc8-4ac0-8751-d0c039bbc9fb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: sqlite update on CentOS 7 for latest django version

2019-07-18 Thread Tal
Got it.
For anyone also trying this, on a fresh CentOS 7 minimal install, do this 
as root:

   - yum groupinstall "Development Tools"
   - yum install tcl
   - curl -O https://www.sqlite.org/src/tarball/sqlite.tar.gz
   - tar -xvf sqlite.tar.gz
   - cd sqlite/
   - ./configure
   - make
   - cp -v .libs/libsqlite3.so.0.8.6 /usr/local/lib64/
   - Dont miss the dot in .libs
   - echo "/usr/local/lib64" > /etc/ld.so.conf.d/sqlite-x68_64.conf
   - ldconfig

We basically just compiled the sqlite library from source, moved it to 
/usr/local/lib64/, and told the system to use it instead of the original 
/usr/lib64/libsqlite3.so.0.8.6 library it was using.

At this point, if you want, you can delete the sqlite.tar.gz file, and 
sqlite directory with all the source code.
If you ever need to undo this, delete /etc/ld.so.conf.d/sqlite-x68_64.conf, 
delete /usr/local/lib64/libsqlite3.so.0.8.6, and run "ldconfig" as root.

I'll try to add this to the djangoproject ticket as well.

Thanks

On Thursday, July 18, 2019 at 9:07:50 AM UTC-6, Tal wrote:
>
> Yoo - this is a known problem. 
> <https://code.djangoproject.com/ticket/30313> It has nothing to do with 
> running "migrate", being in a virtual environment, or settings.py. 
>
> Jani - I tried compiling the latest Python manually - it was actually 
> super easy - but even with the latest Python, importing _sqlite3 and 
> checking the version, I still see the old version. I don't think sqlite is 
> built into Python anymore - I think sqlite is some sort of library that 
> Python uses. It seems not to be /usr/bin/sqlite3. I think that's just the 
> binary that lets you interact with an sqlite database in the terminal - not 
> the library.
>
> There's an article here 
> <https://charlesleifer.com/blog/compiling-sqlite-for-use-with-python-applications/>
>  
> that tries to cover updating sqlite so your Python picks up on it, but so 
> far, I haven't had any luck getting it to work.
>
>
> On Thursday, July 18, 2019 at 1:14:42 AM UTC-6, Jani Tiainen wrote:
>>
>> Hi.
>>
>> I think Python has built in version so you might need to build custom 
>> version of python.
>>
>> Pyenv is pretty neat tool to handle custom python builds.
>>
>> ke 17. heinäk. 2019 klo 21.36 Tal  kirjoitti:
>>
>>> Or is Python's sqlite built into Python, not depending on 
>>> /usr/bin/sqlite3 at all?
>>> Would I have to recompile Python for a newer version of sqlite that 
>>> django can use?
>>>
>>> PS. I know I can downgrade django. I'm wondering how complex it is to 
>>> compile a new version of sqlite for it to use.
>>>
>>> On Wednesday, July 17, 2019 at 12:14:54 PM UTC-6, Tal wrote:
>>>>
>>>> When using the latest django from PyPI in CentOS 7, running 
>>>> "./manage.py runserver" gives an error about sqlite being too old.
>>>> Since there's no newer sqlite version in the CentOS repos, I tried 
>>>> building sqlite from scratch:
>>>>
>>>> curl -L https://www.sqlite.org/2019/sqlite-amalgamation-329.tar.gz 
>>>> > sqlite-amalgamation-329.tar.gz
>>>> tar -xvf sqlite-amalgamation-329.tar.gzcd sqlite-autoconf-329
>>>> ./configure
>>>> make
>>>> make install
>>>>
>>>>
>>>> This sets up the latest sqlite3 to /usr/local/bin/.
>>>> Since /usr/local/bin is ahead of /usr/bin in my PATH, just running 
>>>> "sqlite3" in the terminal runs the latest sqlite.
>>>> It runs without issues, and shows that it's the latest version:
>>>>
>>>> my_hostname# sqlite3
>>>>
>>>> SQLite version 3.29.0 2019-07-10 17:32:03 
>>>> Enter ".help" for usage hints. 
>>>> Connected to a transient in-memory database. 
>>>> Use ".open FILENAME" to reopen on a persistent database. 
>>>> sqlite>
>>>>
>>>>
>>>> Running "./manage.py runserver" again, it still tries to use the old 
>>>> version in /usr/bin, and fails.
>>>> My django is running in a pipenv virtual environment, where PATH still 
>>>> has /usr/local/bin/ ahead of /usr/bin, and running "sqlite3" in terminal 
>>>> still shows the latest version.
>>>>
>>>> I followed the traceback django gives me to the dbapi2.py module, where 
>>>> to figure out the sqlite version it does this:
>>>>
>>>> import _sqlite3
>>>> _sqlite3.sqlite_version
>>&

Re: sqlite update on CentOS 7 for latest django version

2019-07-18 Thread Tal
Yoo - this is a known problem. <https://code.djangoproject.com/ticket/30313> It 
has nothing to do with running "migrate", being in a virtual environment, 
or settings.py. 

Jani - I tried compiling the latest Python manually - it was actually super 
easy - but even with the latest Python, importing _sqlite3 and checking the 
version, I still see the old version. I don't think sqlite is built into 
Python anymore - I think sqlite is some sort of library that Python uses. 
It seems not to be /usr/bin/sqlite3. I think that's just the binary that 
lets you interact with an sqlite database in the terminal - not the library.

There's an article here 
<https://charlesleifer.com/blog/compiling-sqlite-for-use-with-python-applications/>
 
that tries to cover updating sqlite so your Python picks up on it, but so 
far, I haven't had any luck getting it to work.


On Thursday, July 18, 2019 at 1:14:42 AM UTC-6, Jani Tiainen wrote:
>
> Hi.
>
> I think Python has built in version so you might need to build custom 
> version of python.
>
> Pyenv is pretty neat tool to handle custom python builds.
>
> ke 17. heinäk. 2019 klo 21.36 Tal > 
> kirjoitti:
>
>> Or is Python's sqlite built into Python, not depending on 
>> /usr/bin/sqlite3 at all?
>> Would I have to recompile Python for a newer version of sqlite that 
>> django can use?
>>
>> PS. I know I can downgrade django. I'm wondering how complex it is to 
>> compile a new version of sqlite for it to use.
>>
>> On Wednesday, July 17, 2019 at 12:14:54 PM UTC-6, Tal wrote:
>>>
>>> When using the latest django from PyPI in CentOS 7, running "./manage.py 
>>> runserver" gives an error about sqlite being too old.
>>> Since there's no newer sqlite version in the CentOS repos, I tried 
>>> building sqlite from scratch:
>>>
>>> curl -L https://www.sqlite.org/2019/sqlite-amalgamation-329.tar.gz 
>>> > sqlite-amalgamation-329.tar.gz
>>> tar -xvf sqlite-amalgamation-329.tar.gzcd sqlite-autoconf-329
>>> ./configure
>>> make
>>> make install
>>>
>>>
>>> This sets up the latest sqlite3 to /usr/local/bin/.
>>> Since /usr/local/bin is ahead of /usr/bin in my PATH, just running 
>>> "sqlite3" in the terminal runs the latest sqlite.
>>> It runs without issues, and shows that it's the latest version:
>>>
>>> my_hostname# sqlite3
>>>
>>> SQLite version 3.29.0 2019-07-10 17:32:03 
>>> Enter ".help" for usage hints. 
>>> Connected to a transient in-memory database. 
>>> Use ".open FILENAME" to reopen on a persistent database. 
>>> sqlite>
>>>
>>>
>>> Running "./manage.py runserver" again, it still tries to use the old 
>>> version in /usr/bin, and fails.
>>> My django is running in a pipenv virtual environment, where PATH still 
>>> has /usr/local/bin/ ahead of /usr/bin, and running "sqlite3" in terminal 
>>> still shows the latest version.
>>>
>>> I followed the traceback django gives me to the dbapi2.py module, where 
>>> to figure out the sqlite version it does this:
>>>
>>> import _sqlite3
>>> _sqlite3.sqlite_version
>>>
>>>
>>> If I run "python" in my virtualenv, and type those 2 lines, it shows the 
>>> old version of sqlite too.
>>> _sqlite3 is not written in python - it's a compiled binary, so I can't 
>>> examine it to see where it looks.
>>>
>>> Am I missing something?
>>> How can I tell _sqlite3 that there's a newer version of sqlite available 
>>> on the system?
>>> Does _sqlite3 even care about /usr/local/bin/sqlite3? Or is there some 
>>> sqlite library it's looking for?
>>>
>> -- 
>> 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...@googlegroups.com .
>> To post to this group, send email to django...@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/3d011ce9-c849-48a7-82be-0ea08edb4566%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/3d011ce9-c849-48a7-82be-0ea08edb4566%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> 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/589b6a4a-c27f-4128-ba1d-f98f24d35eae%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: sqlite update on CentOS 7 for latest django version

2019-07-17 Thread Tal
Or is Python's sqlite built into Python, not depending on /usr/bin/sqlite3 
at all?
Would I have to recompile Python for a newer version of sqlite that django 
can use?

PS. I know I can downgrade django. I'm wondering how complex it is to 
compile a new version of sqlite for it to use.

On Wednesday, July 17, 2019 at 12:14:54 PM UTC-6, Tal wrote:
>
> When using the latest django from PyPI in CentOS 7, running "./manage.py 
> runserver" gives an error about sqlite being too old.
> Since there's no newer sqlite version in the CentOS repos, I tried 
> building sqlite from scratch:
>
> curl -L https://www.sqlite.org/2019/sqlite-amalgamation-329.tar.gz > 
> sqlite-amalgamation-329.tar.gz
> tar -xvf sqlite-amalgamation-329.tar.gzcd sqlite-autoconf-329
> ./configure
> make
> make install
>
>
> This sets up the latest sqlite3 to /usr/local/bin/.
> Since /usr/local/bin is ahead of /usr/bin in my PATH, just running 
> "sqlite3" in the terminal runs the latest sqlite.
> It runs without issues, and shows that it's the latest version:
>
> my_hostname# sqlite3
>
> SQLite version 3.29.0 2019-07-10 17:32:03 
> Enter ".help" for usage hints. 
> Connected to a transient in-memory database. 
> Use ".open FILENAME" to reopen on a persistent database. 
> sqlite>
>
>
> Running "./manage.py runserver" again, it still tries to use the old 
> version in /usr/bin, and fails.
> My django is running in a pipenv virtual environment, where PATH still has 
> /usr/local/bin/ ahead of /usr/bin, and running "sqlite3" in terminal still 
> shows the latest version.
>
> I followed the traceback django gives me to the dbapi2.py module, where to 
> figure out the sqlite version it does this:
>
> import _sqlite3
> _sqlite3.sqlite_version
>
>
> If I run "python" in my virtualenv, and type those 2 lines, it shows the 
> old version of sqlite too.
> _sqlite3 is not written in python - it's a compiled binary, so I can't 
> examine it to see where it looks.
>
> Am I missing something?
> How can I tell _sqlite3 that there's a newer version of sqlite available 
> on the system?
> Does _sqlite3 even care about /usr/local/bin/sqlite3? Or is there some 
> sqlite library it's looking for?
>

-- 
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/3d011ce9-c849-48a7-82be-0ea08edb4566%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


sqlite update on CentOS 7 for latest django version

2019-07-17 Thread Tal
When using the latest django from PyPI in CentOS 7, running "./manage.py 
runserver" gives an error about sqlite being too old.
Since there's no newer sqlite version in the CentOS repos, I tried building 
sqlite from scratch:

curl -L https://www.sqlite.org/2019/sqlite-amalgamation-329.tar.gz > 
sqlite-amalgamation-329.tar.gz
tar -xvf sqlite-amalgamation-329.tar.gzcd sqlite-autoconf-329
./configure
make
make install


This sets up the latest sqlite3 to /usr/local/bin/.
Since /usr/local/bin is ahead of /usr/bin in my PATH, just running 
"sqlite3" in the terminal runs the latest sqlite.
It runs without issues, and shows that it's the latest version:

my_hostname# sqlite3

SQLite version 3.29.0 2019-07-10 17:32:03 
Enter ".help" for usage hints. 
Connected to a transient in-memory database. 
Use ".open FILENAME" to reopen on a persistent database. 
sqlite>


Running "./manage.py runserver" again, it still tries to use the old 
version in /usr/bin, and fails.
My django is running in a pipenv virtual environment, where PATH still has 
/usr/local/bin/ ahead of /usr/bin, and running "sqlite3" in terminal still 
shows the latest version.

I followed the traceback django gives me to the dbapi2.py module, where to 
figure out the sqlite version it does this:

import _sqlite3
_sqlite3.sqlite_version


If I run "python" in my virtualenv, and type those 2 lines, it shows the 
old version of sqlite too.
_sqlite3 is not written in python - it's a compiled binary, so I can't 
examine it to see where it looks.

Am I missing something?
How can I tell _sqlite3 that there's a newer version of sqlite available on 
the system?
Does _sqlite3 even care about /usr/local/bin/sqlite3? Or is there some 
sqlite library it's looking for?

-- 
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/baa28569-b18c-423e-b6a5-60e619808503%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


What's the best way to have app access permissions?

2019-07-16 Thread Tal
I know you can have permissions on individual models that control which 
users have access to them, but I need something for my apps.

Ex. If a user logs in, does he have access to the store_app? The forum_app? 
etc.

I have a solution that looks something like this:

models.py:

class MyUser(AbstractUser):
for app_short_name, app_long_name in settings.APP_CHOICES:
add_field = "allow_{} = ".format(app_short_name)
add_field += "models.BooleanField(verbose_name='Allow Access to 
{}', default=False, null=False)".format(app_long_name)

exec(add_field)


settings.py:

APP_CHOICES = [ 
('store_app', 'Store App'),
('forum_app', 'Forum App'),
]

It works, but I'm not sure if it's bad practice to have dynamically 
generated fields in models.py like this, or if there's a better/simpler way 
to do this.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e2672373-5cc1-495d-8d46-5e99bdf58fbe%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Game on Python

2019-06-25 Thread Ido Tal

a = input("p")
p = 0
if a=="enis":
print("correct!!!")
p += 1
else :
print("incorrect!!!")
print("The Answer was penis")

print("you have " + str( p ) + " points")
b = input("d")
if b=="ick":
print("correct!!!")
p += 1
else :
print("incorrect!!!")
print("The Answer was dick")

print("you have " + str( p ) + " points")
c = input("v")
if c=="agina":
print("correct!!!")
p += 1
else :
print("incorrect!!!")
print("The Answer was vagina")

print("you have " + str( p ) + " points")
d = input("f")
if d=="uck":
print("correct!!!")
p += 1
else :
print("incorrect!!!")
print("The Answer was fuck")

print("you have " + str( p ) + " points")
e = input("n")
if e=="igga":
print("correct!!!")
p += 1
else :
print("incorrect!!!")
print("The Answer was nigga")

print("you have " + str( p ) + " points")
f = input("r")
if f=="ape":
print("correct!!!")
p += 1
else :
print("incorrect!!!")
print("The Answer was rape")

print("you have " + str( p ) + " points")
g = input("ga")
if g=="ndhi":
print("correct!!!")
p += 1
else :
print("incorrect!!!")
print("The Answer was gandhi")

print("you have " + str( p ) + " points")
h = input("l")
if h=="igma":
print("correct!!!")
p += 1
else :
print("incorrect!!!")
print("The Answer was ligma")

print("you have " + str( p ) + " points")
i = input("a")
if i=="ss":
print("correct!!!")
p += 1
else :
print("incorrect!!!")
print("The Answer was ass")

print("you have " + str( p ) + " points")
j = input("b")
if j=="oobs":
print("correct!!!")
p += 1
else :
print("incorrect!!!")
print("The Answer was boobs")

print("you have " + str( p ) + " points")



k = input("b")
if k=="itch":
print("correct!!!")
p += 1
else :
print("incorrect!!!")
print("The Answer was bitch")

print("you have " + str( p ) + " points")

l = input("se")
if l=="x":
print("correct!!!")
p += 1
else :
print("incorrect!!!")
print("The Answer was sex")

print("you have " + str( p ) + " points")

m = input("ta")
if m=="mpon":
print("correct!!!")
p += 1
else :
print("incorrect!!!")
print("The Answer was tampon")

print("you have " + str( p ) + " points")

n = input("bu")
if n=="tt":
print("correct!!!")
p += 1
else :
print("incorrect!!!")
print("The Answer was butt")

print("you have " + str( p ) + " points")

o = input("er")
if o=="ection":
print("correct!!!")
p += 1
else :
print("incorrect!!!")
print("The Answer was erection")

print("you have " + str( p ) + " points")

q = input("H")
if q=="IV":
print("correct!!!")
p += 1
else :
print("incorrect!!!")
print("The Answer was HIV")

print("you have " + str( p ) + " points")

r = input("con")
if r=="dom":
print("correct!!!")
p += 1
else :
print("incorrect!!!")
print("The Answer was condom")

print("you have " + str( p ) + " points")

s = input("c")
if s=="um":
print("correct!!!")
p += 1
else :
print("incorrect!!!")
print("The Answer was cum")

print("you have " + str( p ) + " points")

t = input("co")
if t=="ck":
print("correct!!!")
p += 1
else :
print("incorrect!!!")
print("The Answer was cock")

print("you have " + str( p ) + " points")

x = input("I am ")
p = 0

if x == "gay":
print("Correct!!!")
p += 1
print("You have " + str(p) + " points!")
else:
print("Incorrect!!!")
print("The correct answer was 'gay'")
print("You have " + str(p) + " points!")


x = input("You are a ")
if x == "virgin":
print("Correct!!!")
p += 1
print("You have " + str(p) + " points!")
else:
print("Incorrect!!!")
print("The correct answer was 'virgin'")
print("You have " + str(p) + " points!")


x = input("Black people have big ")
if x == "peepees":
print("Correct!!!")
p += 1
print("You have " + str(p) + "points!")
else:
print("Incorrect!!!")
print("The correct answer was 'peepees'")
print("You have " + str(p) + " points!")  

x = input("I need to ")
if x == "cum":
print("Correct!!!")
p += 1
print("You have " + str(p) + " points")
else:
print("Incorrect!!!")
print("The correct answer was 'cum'")
print("You have " + str(p) + " points!")

-- 
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/e9aab1ad-5924-4ded-a2fa-24d4cfafc7ca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: What's the best way to inherit boolean values from a model?

2019-06-05 Thread Tal
Didn't know it was so simple to do that - I'll make sure to do it.
Thanks


On Wednesday, June 5, 2019 at 9:32:30 AM UTC-6, RyuCoder wrote:
>
> RE : If companies permissions are updated, all of its employees 
> permissions needs to be updated as well. 
>
> Just make sure to use transaction for this.
> e.g. 
>
> from django.db import DatabaseError, transaction
> with transaction.atomic():
> # code to update company permissions 
>
> # code to update its employees permissions
>
> pass
>
>
>
>
> Regards,
> Chetan Ganji
> +91-900-483-4183
> ganji...@gmail.com 
> http://ryucoder.in
>
>
> On Wed, Jun 5, 2019 at 8:52 PM Tal > wrote:
>
>> Awesome! Simple and DRY. Thanks!
>>
>> On Wednesday, June 5, 2019 at 5:07:17 AM UTC-6, RyuCoder wrote:
>>>
>>> No need for inherit permissions.  As it will increase one more if 
>>> condition to be checked. 
>>> But, whenever a new user is created, you have to read the values from 
>>> its companys permissions and set them for the current user. 
>>> If companies permissions are updated, all of its employees permissions 
>>> needs to be updated as well. 
>>>
>>> This is a typical example of a Nested CRUD. 
>>>
>>>
>>>
>>> class BasePermissions(models.Model):
>>> allow_blog_access = models.BooleanField(default=True)
>>> allow_shop_access = models.BooleanField(default=True)
>>> allow_admin_access = models.BooleanField(default=True)
>>>
>>> class Meta:
>>> abstract = True
>>>
>>>
>>> class Company(BasePermissions):
>>> name = models.CharField(max_length=255)
>>>
>>>
>>> class CustomUser(BasePermissions, AbstractUser):
>>> company = models.ForeignKey(Company, on_delete=models.CASCADE, 
>>> related_name="customuser")
>>>
>>>
>>>
>>> Cheers!
>>>
>>>
>>> Regards,
>>> Chetan Ganji
>>> +91-900-483-4183
>>> ganji...@gmail.com
>>> http://ryucoder.in
>>>
>>>
>>> On Wed, Jun 5, 2019 at 4:26 AM Tal  wrote:
>>>
>>>> Lets say I have 2 models:
>>>>
>>>>
>>>> class Company(models.Model):
>>>>  name = models.CharField(...)
>>>>  allow_blog_access = models.BooleanField(...)
>>>>  allow_shop_access = models.BooleanField(...)
>>>>  allow_admin_access = models.BooleanField(...)
>>>>
>>>>
>>>> class User(AbstractUser):
>>>>  company = models.ForeignKey(Company, ...)
>>>>  ...
>>>>
>>>>
>>>>
>>>> Here, users can be assigned to a company, and when a user tries to 
>>>> access a particular webpage,
>>>> the view can check:
>>>>
>>>>- Does this user's company have access to this area (ex. the blog 
>>>>app)?
>>>>
>>>>
>>>> This is great. That means access to particular areas (or apps) of the 
>>>> site can be controlled at the company level.
>>>> When you create a user, you just assign him to a company, and whatever 
>>>> the company is allowed to access, he is
>>>> as well. It makes updating access a lot easier too, when you can change 
>>>> it in one place (at the company level), instead
>>>> of doing it for every user.
>>>>
>>>> The problem I'm having is that one or two users that are part of a 
>>>> particular company need access to most of, but
>>>> not all of, the areas the company has access to.
>>>>
>>>> What's the best way to implement this?
>>>>
>>>> The main thing I can think of is to have the User class also have 
>>>> Boolean fields for allow_blog_access, allow_shop_access
>>>> and allow_admin_access, but add another field called 
>>>> inherit_permissions (also boolean). It would look like this:
>>>>
>>>>
>>>> class Company(models.Model):
>>>>  name = models.CharField(...)
>>>>  allow_blog_access = models.BooleanField(...)
>>>>  allow_shop_access = models.BooleanField(...)
>>>>  allow_admin_access = models.BooleanField(...)
>>>>
>>>>
>>>> class User(AbstractUser):
>>>>  company = models.ForeignKey(Company, ...)
>>>>  allow_blog_access = models.BooleanField(...)
>>>>  allow_shop_access = models.BooleanField(...

Re: What's the best way to inherit boolean values from a model?

2019-06-05 Thread Tal
Awesome! Simple and DRY. Thanks!

On Wednesday, June 5, 2019 at 5:07:17 AM UTC-6, RyuCoder wrote:
>
> No need for inherit permissions.  As it will increase one more if 
> condition to be checked. 
> But, whenever a new user is created, you have to read the values from its 
> companys permissions and set them for the current user. 
> If companies permissions are updated, all of its employees permissions 
> needs to be updated as well. 
>
> This is a typical example of a Nested CRUD. 
>
>
>
> class BasePermissions(models.Model):
> allow_blog_access = models.BooleanField(default=True)
> allow_shop_access = models.BooleanField(default=True)
> allow_admin_access = models.BooleanField(default=True)
>
> class Meta:
> abstract = True
>
>
> class Company(BasePermissions):
> name = models.CharField(max_length=255)
>
>
> class CustomUser(BasePermissions, AbstractUser):
> company = models.ForeignKey(Company, on_delete=models.CASCADE, 
> related_name="customuser")
>
>
>
> Cheers!
>
>
> Regards,
> Chetan Ganji
> +91-900-483-4183
> ganji...@gmail.com 
> http://ryucoder.in
>
>
> On Wed, Jun 5, 2019 at 4:26 AM Tal > wrote:
>
>> Lets say I have 2 models:
>>
>>
>> class Company(models.Model):
>>  name = models.CharField(...)
>>  allow_blog_access = models.BooleanField(...)
>>  allow_shop_access = models.BooleanField(...)
>>  allow_admin_access = models.BooleanField(...)
>>
>>
>> class User(AbstractUser):
>>  company = models.ForeignKey(Company, ...)
>>  ...
>>
>>
>>
>> Here, users can be assigned to a company, and when a user tries to access 
>> a particular webpage,
>> the view can check:
>>
>>- Does this user's company have access to this area (ex. the blog 
>>app)?
>>
>>
>> This is great. That means access to particular areas (or apps) of the 
>> site can be controlled at the company level.
>> When you create a user, you just assign him to a company, and whatever 
>> the company is allowed to access, he is
>> as well. It makes updating access a lot easier too, when you can change 
>> it in one place (at the company level), instead
>> of doing it for every user.
>>
>> The problem I'm having is that one or two users that are part of a 
>> particular company need access to most of, but
>> not all of, the areas the company has access to.
>>
>> What's the best way to implement this?
>>
>> The main thing I can think of is to have the User class also have Boolean 
>> fields for allow_blog_access, allow_shop_access
>> and allow_admin_access, but add another field called inherit_permissions 
>> (also boolean). It would look like this:
>>
>>
>> class Company(models.Model):
>>  name = models.CharField(...)
>>  allow_blog_access = models.BooleanField(...)
>>  allow_shop_access = models.BooleanField(...)
>>  allow_admin_access = models.BooleanField(...)
>>
>>
>> class User(AbstractUser):
>>  company = models.ForeignKey(Company, ...)
>>  allow_blog_access = models.BooleanField(...)
>>  allow_shop_access = models.BooleanField(...)
>>  allow_admin_access = models.BooleanField(...)
>>  inherit_permission = models.BooleanField(...)
>>  ...
>>
>>
>>
>> If inherit_permissions for a user is set, the view should look at the 
>> permissions of the company the user belongs to 
>> (request.user.company.allow_blog_access).
>> If inherit_permissions for a user is not set, the view should look at the 
>> permissions of the user (request.user.allow_blog_access).
>>
>> Is there a better way to do this? Or is that the simplest?
>>
>> -- 
>> 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...@googlegroups.com .
>> To post to this group, send email to django...@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/c0051d28-de5d-427f-87da-4bd986734f69%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/c0051d28-de5d-427f-87da-4bd986734f69%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> 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/1ad82488-02c3-482a-ba84-fc529c066967%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


What's the best way to inherit boolean values from a model?

2019-06-04 Thread Tal
Lets say I have 2 models:


class Company(models.Model):
 name = models.CharField(...)
 allow_blog_access = models.BooleanField(...)
 allow_shop_access = models.BooleanField(...)
 allow_admin_access = models.BooleanField(...)


class User(AbstractUser):
 company = models.ForeignKey(Company, ...)
 ...



Here, users can be assigned to a company, and when a user tries to access a 
particular webpage,
the view can check:

   - Does this user's company have access to this area (ex. the blog app)?


This is great. That means access to particular areas (or apps) of the site 
can be controlled at the company level.
When you create a user, you just assign him to a company, and whatever the 
company is allowed to access, he is
as well. It makes updating access a lot easier too, when you can change it 
in one place (at the company level), instead
of doing it for every user.

The problem I'm having is that one or two users that are part of a 
particular company need access to most of, but
not all of, the areas the company has access to.

What's the best way to implement this?

The main thing I can think of is to have the User class also have Boolean 
fields for allow_blog_access, allow_shop_access
and allow_admin_access, but add another field called inherit_permissions 
(also boolean). It would look like this:


class Company(models.Model):
 name = models.CharField(...)
 allow_blog_access = models.BooleanField(...)
 allow_shop_access = models.BooleanField(...)
 allow_admin_access = models.BooleanField(...)


class User(AbstractUser):
 company = models.ForeignKey(Company, ...)
 allow_blog_access = models.BooleanField(...)
 allow_shop_access = models.BooleanField(...)
 allow_admin_access = models.BooleanField(...)
 inherit_permission = models.BooleanField(...)
 ...



If inherit_permissions for a user is set, the view should look at the 
permissions of the company the user belongs to 
(request.user.company.allow_blog_access).
If inherit_permissions for a user is not set, the view should look at the 
permissions of the user (request.user.allow_blog_access).

Is there a better way to do this? Or is that the simplest?

-- 
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/c0051d28-de5d-427f-87da-4bd986734f69%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Static files in production [Was: How does WSGI work?]

2019-03-08 Thread Tal
Ok - maybe I'll try to get a hold of Grahame Dumpleton when I have some 
time.

Thanks guys

PS.

Python frameworks like Flask or Django are good at making decisions about 
what response to return for a given request, and returning it.
In most cases, that response is an HTML page, or json, or something similar.
If a request comes that requires you to return a file however, this is best 
done by your web server software (nginx, apache, etc).
It can do it way more efficiently.
In production, if you set everything up as recommended, the request 
initially hits your web server, which decides if the request should be sent 
to Django, or if a file should be returned directly.
That decision is usually easy to make for the web server because all static 
files (files that never change, like images) are all in the same directory.
When you are writing your django project, you'll probably have individual 
static directories for every app.
As Mike pointed out, the "./manage.py collectstatic" command will gather 
all these static files from all your apps into a single folder, so that
your web server can easily determine if it should return a static file from 
that folder, or send the request to django.


On Thursday, March 7, 2019 at 6:41:39 PM UTC-7, Mike Dewhirst wrote:
>
> On 8/03/2019 11:54 am, Joel Mathew wrote: 
> > There's a mod_wsgi_express thread that Graham monitors, so he's sure 
> > to get feedback from there 
> > 
> > Understanding this better could help me solve static file blues. Most 
> > of the time I don't understand why my static files fine aren't served 
> > when I move to production. 
>
> Usually it is because they are in the wrong place. 
>
> Your production webserver (in my case Apache) probably wants to serve 
> the static files directly without Django getting involved at all. There 
> should be an alias directive in your webserver conf which specifies the 
> actual location of your static files base directory and equates that 
> with the STATIC_URL value in your settings. Similarly for the MEDIA_URL 
> value. 
>
> All you really need to do is write a script to copy your static files 
> from where they live in your dev environment to the location specified 
> by STATIC_URL in your production environment. 
>
> Alternatively, manage.py collectstatic will do that for you. 
>
> > 
> > On Fri, 8 Mar, 2019, 5:29 AM Mike Dewhirst,   
> > <mailto:mi...@dewhirst.com.au >> wrote: 
> > 
> > On 8/03/2019 10:11 am, Tal wrote: 
> > > The word "simple" appears 13 times in PEP, but no one knows 
> how 
> > > this magical specification works? 
> > > Can anyone confirm I'm not crazy please? 
> > 
> > You could try writing to Grahame Dumpleton for confirmation. I'm 
> > reasonably sure he wrote mod_wsgi and ought to be able to correct 
> > you if 
> > you've misunderstood anything.He used to give presentations on 
> > wsgi at 
> > PyCons so you might be able to find something on YouTube from a few 
> > years ago. 
> > 
> > Last I heard of him he is fairly focused on Kubernetes so he 
> probably 
> > doesn't monitor the Django list any more. 
> > 
> > > 
> > > On Tuesday, February 26, 2019 at 3:13:00 PM UTC-7, Tal wrote: 
> > > 
> > > Is it right though? 
> > > 
> > > On Tuesday, February 26, 2019 at 2:49:03 PM UTC-7, mike wrote: 
> > > 
> > > Great write up! 
> > > 
> > > On Tue, Feb 26, 2019 at 2:39 PM Tal  > <mailto:tal@gmail.com>> wrote: 
> > > 
> > > Did I get something wrong? 
> > > Do you mean the devs working on the Django project 
> know 
> > > nothing about this, or the devs using Django to 
> > build web 
> > > apps? 
> > > From what I've read, devs using Django don't need to 
> be 
> > >     too familiar with WSGI, but it seems like it helps at 
> > > least having a conceptual understanding of what it is. 
> > > 
> > > On Tuesday, February 26, 2019 at 12:28:26 PM UTC-7, 
> > Motaz 
> > > Hejaze wrote: 
> > > 
> > > You are very close to what realy happens , most of 
> > > devs know nothing aboutbthis stuff 
> > > 
> > > On Tue, 26 Feb 2019, 20:26 Tal, 
> > mailto:tal@gmail.com

Re: How does WSGI work?

2019-03-07 Thread Tal
The word "simple" appears 13 times in PEP, but no one knows how this 
magical specification works?
Can anyone confirm I'm not crazy please?

On Tuesday, February 26, 2019 at 3:13:00 PM UTC-7, Tal wrote:
>
> Is it right though?
>
> On Tuesday, February 26, 2019 at 2:49:03 PM UTC-7, mike wrote:
>>
>> Great write up!
>>
>> On Tue, Feb 26, 2019 at 2:39 PM Tal  wrote:
>>
>>> Did I get something wrong?
>>> Do you mean the devs working on the Django project know nothing about 
>>> this, or the devs using Django to build web apps?
>>> From what I've read, devs using Django don't need to be too familiar 
>>> with WSGI, but it seems like it helps at least having a conceptual 
>>> understanding of what it is.
>>>
>>> On Tuesday, February 26, 2019 at 12:28:26 PM UTC-7, Motaz Hejaze wrote:
>>>>
>>>> You are very close to what realy happens , most of devs know nothing 
>>>> aboutbthis stuff
>>>>
>>>> On Tue, 26 Feb 2019, 20:26 Tal,  wrote:
>>>>
>>>>> I've been developing web applications using Flask and Django for about 
>>>>> a year now, and although I've come across the term WSGI a bunch of times 
>>>>> in 
>>>>> both frameworks, I never really understood what it did. I'm sure I'm not 
>>>>> the only one. The quick explanations I read never made sense to me. Even 
>>>>> PEP didn't really give me a clear picture of how WSGI fits in with 
>>>>> Nginx, and Django. There are a bunch of articles online that quickly show 
>>>>> how to setup nginx, gunicorn/uwsgi and django to work in production, and 
>>>>> once I figured that out, I never really had a reason to figure out WSGI 
>>>>> again. But it's been a year now, and I probably should understand at 
>>>>> least 
>>>>> the basics. 
>>>>>
>>>>> I did a bit more reading recently, and I think I get it. Just looking 
>>>>> for someone to confirm that I'm on the right track.
>>>>> This is how I think it works:
>>>>>
>>>>> My example uses the most common setup I use: Nginx, Gunicorn and Django
>>>>>
>>>>>- When an HTTP request comes in, it hits Nginx first
>>>>>   - Nginx runs multiple processes, and makes sure that 
>>>>>   browsers/clients that have a slow connection don't effect other 
>>>>> clients
>>>>>   - If it's a request for a static file, like a CSS file, JS, 
>>>>>   image, or anything like that, Nginx returns it directly
>>>>>   - If it's a request for anything else, it uses *HTTP* to send 
>>>>>   the request over a Unix socket to Gunicorn
>>>>>  - Doesn't have to be a Unix socket, but if both Nginx and 
>>>>>  Gunicorn are running on the same host, it makes sense to use 
>>>>> Unix sockets
>>>>>  - The main point is that Nginx uses HTTP to communicate with 
>>>>>  Gunicorn
>>>>>   - Gunicorn
>>>>>   - Starts up x worker processes on startup (as many as you tell 
>>>>>   it)
>>>>>   - Each worker process imports your application's code 
>>>>>   (django.core.wsgi.get_wsgi_application() in Django's case)
>>>>>  - The application's code is a callable function
>>>>>  - Gunicorn imports it so that it's ready to make a function 
>>>>>  call to it as soon as an HTTP request comes in
>>>>>   - When an HTTP request comes in from Nginx, Gunicorn will:
>>>>>  - Use its main process to assign the request to a free 
>>>>>  worker process
>>>>>  - The worker process translates the HTTP headers into a 
>>>>>  python dictionary (commonly called the 'environment' dictionary)
>>>>>  - The worker process makes a function call to your 
>>>>>  application, passing it the 'environment' dictionary, and a 
>>>>> start_response 
>>>>>  function
>>>>>   - When your application (Django) decides what to do about the 
>>>>>request, and decides to formulate a response, it will:
>>>>>   - Call start_response, giving it the HTTP response 

Re: How does WSGI work?

2019-02-26 Thread Tal
Is it right though?

On Tuesday, February 26, 2019 at 2:49:03 PM UTC-7, mike wrote:
>
> Great write up!
>
> On Tue, Feb 26, 2019 at 2:39 PM Tal > 
> wrote:
>
>> Did I get something wrong?
>> Do you mean the devs working on the Django project know nothing about 
>> this, or the devs using Django to build web apps?
>> From what I've read, devs using Django don't need to be too familiar with 
>> WSGI, but it seems like it helps at least having a conceptual understanding 
>> of what it is.
>>
>> On Tuesday, February 26, 2019 at 12:28:26 PM UTC-7, Motaz Hejaze wrote:
>>>
>>> You are very close to what realy happens , most of devs know nothing 
>>> aboutbthis stuff
>>>
>>> On Tue, 26 Feb 2019, 20:26 Tal,  wrote:
>>>
>>>> I've been developing web applications using Flask and Django for about 
>>>> a year now, and although I've come across the term WSGI a bunch of times 
>>>> in 
>>>> both frameworks, I never really understood what it did. I'm sure I'm not 
>>>> the only one. The quick explanations I read never made sense to me. Even 
>>>> PEP didn't really give me a clear picture of how WSGI fits in with 
>>>> Nginx, and Django. There are a bunch of articles online that quickly show 
>>>> how to setup nginx, gunicorn/uwsgi and django to work in production, and 
>>>> once I figured that out, I never really had a reason to figure out WSGI 
>>>> again. But it's been a year now, and I probably should understand at least 
>>>> the basics. 
>>>>
>>>> I did a bit more reading recently, and I think I get it. Just looking 
>>>> for someone to confirm that I'm on the right track.
>>>> This is how I think it works:
>>>>
>>>> My example uses the most common setup I use: Nginx, Gunicorn and Django
>>>>
>>>>- When an HTTP request comes in, it hits Nginx first
>>>>   - Nginx runs multiple processes, and makes sure that 
>>>>   browsers/clients that have a slow connection don't effect other 
>>>> clients
>>>>   - If it's a request for a static file, like a CSS file, JS, 
>>>>   image, or anything like that, Nginx returns it directly
>>>>   - If it's a request for anything else, it uses *HTTP* to send 
>>>>   the request over a Unix socket to Gunicorn
>>>>  - Doesn't have to be a Unix socket, but if both Nginx and 
>>>>  Gunicorn are running on the same host, it makes sense to use Unix 
>>>> sockets
>>>>  - The main point is that Nginx uses HTTP to communicate with 
>>>>  Gunicorn
>>>>   - Gunicorn
>>>>   - Starts up x worker processes on startup (as many as you tell 
>>>>   it)
>>>>   - Each worker process imports your application's code 
>>>>   (django.core.wsgi.get_wsgi_application() in Django's case)
>>>>  - The application's code is a callable function
>>>>  - Gunicorn imports it so that it's ready to make a function 
>>>>  call to it as soon as an HTTP request comes in
>>>>   - When an HTTP request comes in from Nginx, Gunicorn will:
>>>>  - Use its main process to assign the request to a free worker 
>>>>  process
>>>>  - The worker process translates the HTTP headers into a 
>>>>  python dictionary (commonly called the 'environment' dictionary)
>>>>  - The worker process makes a function call to your 
>>>>  application, passing it the 'environment' dictionary, and a 
>>>> start_response 
>>>>  function
>>>>   - When your application (Django) decides what to do about the 
>>>>request, and decides to formulate a response, it will:
>>>>   - Call start_response, giving it the HTTP response status (eg. 
>>>>   200 OK), and the HTTP response headers as a Python object (list of 
>>>> tuples)
>>>>   - Note: At this point, nothing is sent to the client's browser, 
>>>>  or even Nginx yet
>>>>   - *Return* the body of the response as an iterable
>>>>- Gunicorn will then:
>>>>   - Add any required HTTP headers the application didn't provide
>>>>   - Turn the status, headers a

Re: How does WSGI work?

2019-02-26 Thread Tal
Did I get something wrong?
Do you mean the devs working on the Django project know nothing about this, 
or the devs using Django to build web apps?
>From what I've read, devs using Django don't need to be too familiar with 
WSGI, but it seems like it helps at least having a conceptual understanding 
of what it is.

On Tuesday, February 26, 2019 at 12:28:26 PM UTC-7, Motaz Hejaze wrote:
>
> You are very close to what realy happens , most of devs know nothing 
> aboutbthis stuff
>
> On Tue, 26 Feb 2019, 20:26 Tal, > wrote:
>
>> I've been developing web applications using Flask and Django for about a 
>> year now, and although I've come across the term WSGI a bunch of times in 
>> both frameworks, I never really understood what it did. I'm sure I'm not 
>> the only one. The quick explanations I read never made sense to me. Even 
>> PEP didn't really give me a clear picture of how WSGI fits in with 
>> Nginx, and Django. There are a bunch of articles online that quickly show 
>> how to setup nginx, gunicorn/uwsgi and django to work in production, and 
>> once I figured that out, I never really had a reason to figure out WSGI 
>> again. But it's been a year now, and I probably should understand at least 
>> the basics. 
>>
>> I did a bit more reading recently, and I think I get it. Just looking for 
>> someone to confirm that I'm on the right track.
>> This is how I think it works:
>>
>> My example uses the most common setup I use: Nginx, Gunicorn and Django
>>
>>- When an HTTP request comes in, it hits Nginx first
>>   - Nginx runs multiple processes, and makes sure that 
>>   browsers/clients that have a slow connection don't effect other clients
>>   - If it's a request for a static file, like a CSS file, JS, image, 
>>   or anything like that, Nginx returns it directly
>>   - If it's a request for anything else, it uses *HTTP* to send the 
>>   request over a Unix socket to Gunicorn
>>  - Doesn't have to be a Unix socket, but if both Nginx and 
>>  Gunicorn are running on the same host, it makes sense to use Unix 
>> sockets
>>  - The main point is that Nginx uses HTTP to communicate with 
>>  Gunicorn
>>   - Gunicorn
>>   - Starts up x worker processes on startup (as many as you tell it)
>>   - Each worker process imports your application's code 
>>   (django.core.wsgi.get_wsgi_application() in Django's case)
>>  - The application's code is a callable function
>>  - Gunicorn imports it so that it's ready to make a function 
>>  call to it as soon as an HTTP request comes in
>>   - When an HTTP request comes in from Nginx, Gunicorn will:
>>  - Use its main process to assign the request to a free worker 
>>  process
>>  - The worker process translates the HTTP headers into a python 
>>  dictionary (commonly called the 'environment' dictionary)
>>  - The worker process makes a function call to your application, 
>>  passing it the 'environment' dictionary, and a start_response 
>> function
>>   - When your application (Django) decides what to do about the 
>>request, and decides to formulate a response, it will:
>>   - Call start_response, giving it the HTTP response status (eg. 200 
>>   OK), and the HTTP response headers as a Python object (list of tuples)
>>   - Note: At this point, nothing is sent to the client's browser, or 
>>  even Nginx yet
>>   - *Return* the body of the response as an iterable
>>- Gunicorn will then:
>>   - Add any required HTTP headers the application didn't provide
>>   - Turn the status, headers and body that it received from the 
>>   application into an HTTP response message
>>   - Send the response back to Nginx using HTTP
>>- Nginx will then send the response back to the client
>>
>>
>> So the job of the individual parts is basically this:
>>
>>1. Nginx
>>   - Buffers slow clients
>>   - Quickly serves static files
>>   - Possibly handle SSL, if configured
>>   - Passes HTTP requests to Gunicorn (also using HTTP)
>>   2. Gunicorn
>>   - Deals with TCP connections between nginx and itself
>>  - Prevents your application from needing to do lower-level 
>>  socket stuff with TCP
>>   - Converts HTTP requests into Python objects, and responses back 
>>   into 

How does WSGI work?

2019-02-26 Thread Tal
I've been developing web applications using Flask and Django for about a 
year now, and although I've come across the term WSGI a bunch of times in 
both frameworks, I never really understood what it did. I'm sure I'm not 
the only one. The quick explanations I read never made sense to me. Even 
PEP didn't really give me a clear picture of how WSGI fits in with 
Nginx, and Django. There are a bunch of articles online that quickly show 
how to setup nginx, gunicorn/uwsgi and django to work in production, and 
once I figured that out, I never really had a reason to figure out WSGI 
again. But it's been a year now, and I probably should understand at least 
the basics. 

I did a bit more reading recently, and I think I get it. Just looking for 
someone to confirm that I'm on the right track.
This is how I think it works:

My example uses the most common setup I use: Nginx, Gunicorn and Django

   - When an HTTP request comes in, it hits Nginx first
  - Nginx runs multiple processes, and makes sure that browsers/clients 
  that have a slow connection don't effect other clients
  - If it's a request for a static file, like a CSS file, JS, image, or 
  anything like that, Nginx returns it directly
  - If it's a request for anything else, it uses *HTTP* to send the 
  request over a Unix socket to Gunicorn
 - Doesn't have to be a Unix socket, but if both Nginx and Gunicorn 
 are running on the same host, it makes sense to use Unix sockets
 - The main point is that Nginx uses HTTP to communicate with 
 Gunicorn
  - Gunicorn
  - Starts up x worker processes on startup (as many as you tell it)
  - Each worker process imports your application's code 
  (django.core.wsgi.get_wsgi_application() in Django's case)
 - The application's code is a callable function
 - Gunicorn imports it so that it's ready to make a function call 
 to it as soon as an HTTP request comes in
  - When an HTTP request comes in from Nginx, Gunicorn will:
 - Use its main process to assign the request to a free worker 
 process
 - The worker process translates the HTTP headers into a python 
 dictionary (commonly called the 'environment' dictionary)
 - The worker process makes a function call to your application, 
 passing it the 'environment' dictionary, and a start_response function
  - When your application (Django) decides what to do about the 
   request, and decides to formulate a response, it will:
  - Call start_response, giving it the HTTP response status (eg. 200 
  OK), and the HTTP response headers as a Python object (list of tuples)
  - Note: At this point, nothing is sent to the client's browser, or 
 even Nginx yet
  - *Return* the body of the response as an iterable
   - Gunicorn will then:
  - Add any required HTTP headers the application didn't provide
  - Turn the status, headers and body that it received from the 
  application into an HTTP response message
  - Send the response back to Nginx using HTTP
   - Nginx will then send the response back to the client


So the job of the individual parts is basically this:

   1. Nginx
  - Buffers slow clients
  - Quickly serves static files
  - Possibly handle SSL, if configured
  - Passes HTTP requests to Gunicorn (also using HTTP)
  2. Gunicorn
  - Deals with TCP connections between nginx and itself
 - Prevents your application from needing to do lower-level socket 
 stuff with TCP
  - Converts HTTP requests into Python objects, and responses back into 
  HTTP
   3. Django
  - Just worries about formulating responses to requests, not keeping 
  track of TCP connections, or HTTP, or anything low-level
   

For Apache, they have mod_wsgi, which takes the place of Gunicorn, acting 
as a WSGI server.

That sound right? Or am I way off?

-- 
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/77576c51-8237-46b1-bd48-8f30bbaea3bf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.