Re: Downgrade and Upgrade Django migration

2018-08-05 Thread Melvyn Sopacua
On zaterdag 4 augustus 2018 18:03:21 CEST Andréas Kühne wrote:

> I don't know how to revert migrations though - I do think it's possible

Yes, easy. Name the app and migration you want to downgrade to:

python manage.py yourapp 0002

This would unapply 0003_new_model, 0004_change_new_model and so on.

If you want to unapply all migrations of a given app, then you use "zero":

python manage.py yourapp zero

This unapplies 0001, 0002 etc ...

This is documented at the "migrate" management command[1].

This only works when your migrations have a "reverse" operation coded, where 
RunSQL[2] 
and RunPython[3] is concerned, otherwise the system will not know how to 
unapply the 
migration.

If you want a system that automatically reverts migrations to a set version 
number of the 
entire project, then you'll need to create some custom code and your tools of 
choice will 
be:

- A RunPython migration in the project app, that keeps track of which 
migrations belong to 
which version ... or:
- You squash migrations when cutting a new release and name them consistently 
using "--
squashed-name[4]". For example: coolapp/migrations/0001_v1_0_0.py, 
hotapp/migrations/
0001_v1_0_0.py, coolapp/migrations/0002_v1_0_3.py

With either approach it should be possible to write a management command that 
gathers 
all the migrations to unapply and get back to a fixed point in time.

But what you really have to be aware of, is that it is destructive: if you 
added fields to a 
model and that model has new data in that field during the time it was 
deployed, rolling 
back the migration will destroy that new data.

So while you can go back, you can't easily go forward again and have that data 
magically 
reappear.


https://djangopackages.org/grids/g/versioning/

Probably in addition to custom code.
-- 
Melvyn Sopacua


[1] https://docs.djangoproject.com/en/2.0/ref/django-admin/#migrate
[2] https://docs.djangoproject.com/en/2.0/ref/migration-operations/
#django.db.migrations.operations.RunSQL
[3] https://docs.djangoproject.com/en/2.0/ref/migration-operations/
#django.db.migrations.operations.RunPython
[4] 
https://docs.djangoproject.com/en/2.0/ref/django-admin/#cmdoption-squashmigrations-squashed-name

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


Re: Change the default route of a view

2018-08-05 Thread Jason
well, it was said early on you were avoiding good practices and established 
convention with this, so I'm not surprised its not being incorporated into 
the auto-generated api docs.

-- 
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/9e9121fe-7bf3-448d-a7da-10c253ba8cc7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: main page have stopped work after creating poll app

2018-08-05 Thread Muhammad Ibrahim
After following the due procedure to creating an app polls and running the 
server as guided by Django online tutorial , still can't navigate (The 
current path, polls/, didn't match any of these.) please can you help?.

On Monday, May 28, 2018 at 1:47:09 PM UTC+1, Florian Schweikert wrote:
>
> It seems you don't have a "main" page. 
> The page you saw was a placeholder starting page if there are no other 
> urls defined. 
> If you want to deliver something at / you have to add it to urls.py 
>
>
> PS: pasting screenshots of code is a very bad habit. 
>
> On 26/05/18 14:46, Dmitry Sobolev wrote: 
> > <
> https://lh3.googleusercontent.com/-9lHCmQtIC3A/WwlWrbCUCxI/ZIc/FLzBr-gbHVsbIwQyOBXRaHJnyaPAPQKJQCLcBGAs/s1600/Screen%2BShot%2B2018-05-26%2Bat%2B3.44.00%2BPM.png>
>  
>
> > 
> > if I comment this stroke in urls.py the main page begins to work but in 
> > this case I don't have an access to the polls app. 
> > 
> > 
> > 
> > 
> > суббота, 26 мая 2018 г., 15:00:04 UTC+3 пользователь Dmitry Sobolev 
> написал: 
> > 
> > Hello guys! 
> > I am doing 1st steps in Django. 
> > Started 1st tutorial page 3 times from there and getting the same 
> > case each time. 
> > After that, I created a working "poll app" that works under 
> > 127.0.0.1:8000/polls/  
> > the main address stop working 
> > where should I see the problem of this problem and make main page 
> > work both with "poll app"? 
> > 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...@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/4d392683-e5c3-40fc-98f6-7a0d91e8fa8b%40googlegroups.com
>  
> > <
> https://groups.google.com/d/msgid/django-users/4d392683-e5c3-40fc-98f6-7a0d91e8fa8b%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/3fac6074-f242-4989-9bda-6c87966ffdc4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Change the default route of a view

2018-08-05 Thread Muhammad Ibrahim
Am using django 2.1

On Sun, 05 Aug 2018, 11:25 AM Jason  wrote:

> well, it was said early on you were avoiding good practices and
> established convention with this, so I'm not surprised its not being
> incorporated into the auto-generated api docs.
>
> --
> 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/9e9121fe-7bf3-448d-a7da-10c253ba8cc7%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/CAHqSCSOLECUOjuaiL%2ByJWg7zgAZsiY%3DF0BzW6FO-pQVjhE%2BRZA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Change the default route of a view

2018-08-05 Thread Muhammad Ibrahim
please can you elaborate . Am just a beginner

On Sun, 05 Aug 2018, 11:25 AM Jason  wrote:

> well, it was said early on you were avoiding good practices and
> established convention with this, so I'm not surprised its not being
> incorporated into the auto-generated api docs.
>
> --
> 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/9e9121fe-7bf3-448d-a7da-10c253ba8cc7%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/CAHqSCSPm%3DQ47O0EH0WJuTJVsG7jbsLSPwaRvtn3a5T92f%2B45xQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


value error at dashboard did not return httpresponse

2018-08-05 Thread ireoluwa fakeye


-- 
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/b0cb8738-198f-46f5-b54a-00bd84a2903d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
from django.shortcuts import render
from django.http import HttpResponseRedirect
from django.contrib.auth.models import User
from .form import LoginForm as MyLoginForm
from django.contrib.auth.forms import AuthenticationForm
from django.contrib import messages
from .models import material
from django.http import HttpResponse
from django.shortcuts import render_to_response

from django.contrib.auth.models import User
from django.conf import settings
from django.contrib.auth.hashers import check_password

def home(request):
context= locals()
template='home.html'
return render(request, template, context)
def logins(request):
context=locals()
template='login.html'

return render(request,template,context)   
def signup(request):
context=locals()
template='signup.html'
return render(request,template,context)
def checklogin(request):
if request.method=='POST':
form=MyLoginForm(data=request.POST)
if form.is_valid():
userf=form.Usernames
passes=form.Passwords
g=User.objects.get(Username=userf,Password=passes)
try:
   g=User.objects.get(Username=userf,Password=passes)
except   
CRITICAL=50
messages.add_message(request,CRITICAL,'WRONG USER DETAILS')
return render(request,'login.html')
context={'userf':userf}
return HttpResponseRedirect('/dashboard',context)  

 




def logout(request):
template='home.html'
return render(request,template,context=locals())


   

def dashboard(request,context):

users=context

template='index.html'
render(request,template,{"users":users})

def subcontractors(self,request,dashboard):
total_materials=material.objects.all()
tempelate='basic_table.html' 
return render(request,tempelate,locals())



Re: value error at dashboard did not return httpresponse

2018-08-05 Thread Kasper Laudrup
Return the result of the call to the render function at the end of your 
dashboard function instead of just calling render().

Kind regards,

Kasper Laudrup

On August 5, 2018 4:26:30 PM GMT+02:00, ireoluwa fakeye  
wrote:
>
>
>-- 
>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/b0cb8738-198f-46f5-b54a-00bd84a2903d%40googlegroups.com.
>For more options, visit https://groups.google.com/d/optout.

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.

-- 
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/3E783672-E1F5-44DC-ADA9-72A479A3A127%40stacktrace.dk.
For more options, visit https://groups.google.com/d/optout.


Re: Using the admin navbar & bootstrap throughout my project

2018-08-05 Thread Derek
I also use the admin for the bulk of my project; if you create custom 
pages, you just need to inherit from the standard/default admin template(s) 
and overwrite/extend the relevant template blocks. I'd really recommend you 
figure out how to do this yourself rather than just copy & paste someone 
else's code, as that way you will get to understand something of how the 
framework is put together.  

If you want to see an example of someone making custom pages to fit into 
the admin, have a look at:

https://medium.com/@hakibenita/how-to-turn-django-admin-into-a-lightweight-dashboard-a0e0bbf609ad


On Saturday, 4 August 2018 18:28:27 UTC+2, Conrad Lawes wrote:
>
> Andreas,
>
> You have described perfectly what I need:
> To use the admin backend as my frontend.
>
> Do you have any sample code you could share with me?
>
>
>
> On Saturday, August 4, 2018 at 11:34:07 AM UTC-4, Andréas Kühne wrote:
>>
>> Hi,
>>
>> You could use the admin backend as the frontend for your application. I 
>> have released an application that works that way.
>>
>> However, if you just want to use the layout, you can look into the 
>> contrib.admin package and there you will find all the templates, css and js 
>> required for the admin application. To use it in your application you will 
>> need to do a lot of backwards engineering - but it should be possible,
>>
>> Regards,
>>
>> Andréas
>>
>> 2018-08-04 4:27 GMT+02:00 Conrad Lawes :
>>
>>>
>>> Call me boring but I like the simple elegance of the django admin panel.
>>> I was wondering is there a way use this layout thorough my project.
>>> All the tutorials I have read so far shows how to build your own navbar 
>>> using the various third-party bootstraps and css.
>>> But none shows how use the built-in theme/css/navbar that is  already 
>>> there by default. 
>>>
>>> TIA for your suggestions.
>>>
>>>
>>> -- 
>>> 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...@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/30741bf2-baaf-4b70-9926-32840ea9ef5a%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/427cc364-8cf5-48ec-8551-a5082847a0e0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django Book

2018-08-05 Thread Jun Chen
Does anyone know a good django book for the Django 2.0?

-- 
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/33981edc-bf8f-4b2f-ba3e-5a7612177e1f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Learning django

2018-08-05 Thread Caleb Bryson
Are there any books that teach django for the most recent version out there? I 
have not been successful at finding a book with up to date info

-- 
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/0ef86713-ab00-4ae5-8bc5-9c448b9afa13%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Learning django

2018-08-05 Thread vineeth sagar
Not to be mean or cheeky, but Django documentation is best book imo. Read
the docs, if they are unclear in anyway, Start reading code. That's how I
learnt about sessions and also you'll get to learn all kinds of cool stuff
when you start reading Django code, Like property,cached property, Lazy
evaluation etc.

On Aug 5, 2018 10:29 PM, "Caleb Bryson"  wrote:

> Are there any books that teach django for the most recent version out
> there? I have not been successful at finding a book with up to date info
>
> --
> 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/0ef86713-ab00-4ae5-8bc5-9c448b9afa13%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/CAMMZq8PB2GUgc4h%3DKAQt4Y8n6v9LY9Cp1dmqK-2RNpkHJkwa2A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Book

2018-08-05 Thread Tim Vogt (Tim Vogt)
https://wsvincent.com/about/



> Op 5 aug. 2018, om 17:20 heeft Jun Chen  het volgende 
> geschreven:
> 
> Does anyone know a good django book for the Django 2.0?
> 
> -- 
> 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/33981edc-bf8f-4b2f-ba3e-5a7612177e1f%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/44E08945-A68D-4F8D-A2DC-BC9E1204C9E2%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Channels/Redis fault tolerance with Twemproxy?

2018-08-05 Thread Filbert
Wow, I thought I had this working using haproxy in front of 
redis-sentinel.  haproxy fails over when redis-sentinel fails over within 
30 seconds.

Problem is Daphne (Channels 1.X), reports over and over:

Error trying to receive messages: Error running script (call to 
f_3640886a0c8901ca9188f5f7a5f7a346145b9c5f): @user_script:3: @user_script: 
3: -READONLY You can't write against a read only slave.


Which I assume means Daphne doesn't detect a problem and just keeps the 
socket open on the (old) master that is now the slave.


On Thursday, August 2, 2018 at 8:53:24 PM UTC-4, Andrew Godwin wrote:
>
> Yup, any sort of TCP-level proxy with failover will work for this sort of 
> thing, but you'll likely see some errors whenever you failover as Channels 
> loses its blocking connection that it's using to wait for messages - as 
> always, please test a failover before you rely on it!
>
> Andrew
>
> On Thu, Aug 2, 2018 at 5:50 PM Filbert > 
> wrote:
>
>> Andrew,
>> Just to be clear, there is no reason I can't use haproxy to front end 
>> redis sentinel to effectively hide all this from channels 1 or 2 right?  
>> Very surprised there isn't anyone running this in production that doesn't 
>> need some form of HA.  Buried trying to get a product out the door right 
>> now, but as I get time and more familiar with channels I'll probably dig in 
>> deeper on this.
>> Thanks.
>>
>> On Thursday, August 2, 2018 at 7:32:52 PM UTC-4, Andrew Godwin wrote:
>>>
>>> The Sentinel option was removed in the 2.0 rewrite as it didn't have 
>>> someone to help maintain it (I didn't have the time then and don't right 
>>> now), so you are right, there's currently no easy HA option for Redis with 
>>> Channels.
>>>
>>> If you're interested in one, I can give you some tips on what code needs 
>>> to be written, but it's not something I really want to maintain myself as 
>>> part of the greater Channels effort as HA solutions tend to be quite 
>>> workload-heavy to develop and test and end up being specific to certain 
>>> deployment scenarios. Contributions of code that could help are welcome, 
>>> though.
>>>
>>> Andrew
>>>
>>> On Wed, Aug 1, 2018 at 1:22 PM Filbert  wrote:
>>>
 Well in digging through posts I see Sentinel may be an option, does 
 that mean if my CHANNEL_LAYER would have a single host entry?

 On Wednesday, August 1, 2018 at 9:42:39 AM UTC-4, Filbert wrote:
>
> Thanks Andrew,
> So with a load-balanced ten web server implementation using Channels 
> (and of course ten instances of redis) do I have a HA solution then?  
> RIght 
> now Django settings simply has a list of those servers in CHANNEL_LAYERS, 
> what if (say) three of them crash, will Channels continue to try and hash 
> to the dead servers? Again, I'll accept a brief set of errors, but if 
> this 
> effectively causes Channels to continue to error that is not my 
> definition 
> of HA.
> Thanks.
>
> On Sunday, July 22, 2018 at 8:09:16 PM UTC-4, Andrew Godwin wrote:
>>
>> I don't think redis-cluster supports BLPOP properly still so I don't 
>> think you can use it.
>>
>> Andrew
>>
>> On Sun, Jul 22, 2018 at 12:46 PM Filbert  wrote:
>>
>>> And just to be clear as to my options, using Channels 2.0 I can use 
>>> Redis cluster if I have to to get failover and fault tolerance, correct?
>>>
>>> On Sunday, July 22, 2018 at 12:57:22 PM UTC-4, Andrew Godwin wrote:

 I'm afraid I've never used Twemproxy, so I can't really comment on 
 it, but if you don't care about data loss, it's probably fine?

 Andrew

 On Fri, Jul 20, 2018 at 3:30 PM Filbert  wrote:

> Going to have 10 or more EC2 instances running Channels 2.0.  I 
> really don't want to add the complexity of Redis Cluster or Redis 
> sentinel.  Is a decent fault tolerant solution to implement 
> Twemproxy, 
> instead.  I don't care about data loss if an instance crashes, but I 
> do 
> care that the application continues to operate on the remaining 
> instances.
>
> Is this a workable solution?
>
> -- 
> 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...@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/d1d50730-c1ba-4674-8ef8-54294158d0f6%40googlegroups.com
>  
> 

Re: Channels/Redis fault tolerance with Twemproxy?

2018-08-05 Thread Andrew Godwin
Channels 1 and its Redis bindings have different behaviours to 2, so this
might be improved there (but I can't guarantee it).

Andrew

On Sun, Aug 5, 2018 at 11:48 AM Filbert  wrote:

> Wow, I thought I had this working using haproxy in front of
> redis-sentinel.  haproxy fails over when redis-sentinel fails over within
> 30 seconds.
>
> Problem is Daphne (Channels 1.X), reports over and over:
>
> Error trying to receive messages: Error running script (call to
> f_3640886a0c8901ca9188f5f7a5f7a346145b9c5f): @user_script:3: @user_script:
> 3: -READONLY You can't write against a read only slave.
>
>
> Which I assume means Daphne doesn't detect a problem and just keeps the
> socket open on the (old) master that is now the slave.
>
>
> On Thursday, August 2, 2018 at 8:53:24 PM UTC-4, Andrew Godwin wrote:
>>
>> Yup, any sort of TCP-level proxy with failover will work for this sort of
>> thing, but you'll likely see some errors whenever you failover as Channels
>> loses its blocking connection that it's using to wait for messages - as
>> always, please test a failover before you rely on it!
>>
>> Andrew
>>
>> On Thu, Aug 2, 2018 at 5:50 PM Filbert  wrote:
>>
>>> Andrew,
>>> Just to be clear, there is no reason I can't use haproxy to front end
>>> redis sentinel to effectively hide all this from channels 1 or 2 right?
>>> Very surprised there isn't anyone running this in production that doesn't
>>> need some form of HA.  Buried trying to get a product out the door right
>>> now, but as I get time and more familiar with channels I'll probably dig in
>>> deeper on this.
>>> Thanks.
>>>
>>> On Thursday, August 2, 2018 at 7:32:52 PM UTC-4, Andrew Godwin wrote:

 The Sentinel option was removed in the 2.0 rewrite as it didn't have
 someone to help maintain it (I didn't have the time then and don't right
 now), so you are right, there's currently no easy HA option for Redis with
 Channels.

 If you're interested in one, I can give you some tips on what code
 needs to be written, but it's not something I really want to maintain
 myself as part of the greater Channels effort as HA solutions tend to be
 quite workload-heavy to develop and test and end up being specific to
 certain deployment scenarios. Contributions of code that could help are
 welcome, though.

 Andrew

 On Wed, Aug 1, 2018 at 1:22 PM Filbert  wrote:

> Well in digging through posts I see Sentinel may be an option, does
> that mean if my CHANNEL_LAYER would have a single host entry?
>
> On Wednesday, August 1, 2018 at 9:42:39 AM UTC-4, Filbert wrote:
>>
>> Thanks Andrew,
>> So with a load-balanced ten web server implementation using Channels
>> (and of course ten instances of redis) do I have a HA solution then?  
>> RIght
>> now Django settings simply has a list of those servers in CHANNEL_LAYERS,
>> what if (say) three of them crash, will Channels continue to try and hash
>> to the dead servers? Again, I'll accept a brief set of errors, but if 
>> this
>> effectively causes Channels to continue to error that is not my 
>> definition
>> of HA.
>> Thanks.
>>
>> On Sunday, July 22, 2018 at 8:09:16 PM UTC-4, Andrew Godwin wrote:
>>>
>>> I don't think redis-cluster supports BLPOP properly still so I don't
>>> think you can use it.
>>>
>>> Andrew
>>>
>>> On Sun, Jul 22, 2018 at 12:46 PM Filbert  wrote:
>>>
 And just to be clear as to my options, using Channels 2.0 I can use
 Redis cluster if I have to to get failover and fault tolerance, 
 correct?

 On Sunday, July 22, 2018 at 12:57:22 PM UTC-4, Andrew Godwin wrote:
>
> I'm afraid I've never used Twemproxy, so I can't really comment on
> it, but if you don't care about data loss, it's probably fine?
>
> Andrew
>
> On Fri, Jul 20, 2018 at 3:30 PM Filbert  wrote:
>
>> Going to have 10 or more EC2 instances running Channels 2.0.  I
>> really don't want to add the complexity of Redis Cluster or Redis
>> sentinel.  Is a decent fault tolerant solution to implement 
>> Twemproxy,
>> instead.  I don't care about data loss if an instance crashes, but I 
>> do
>> care that the application continues to operate on the remaining 
>> instances.
>>
>> Is this a workable solution?
>>
>> --
>> 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...@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
>> h

How to use RSA-SHA256 in python using private key

2018-08-05 Thread prakash sharma
Hi all,
I am stuck while salesforce jwt-bearer auth.
I need help in this code section:

String key='x';

Blob privateKey = EncodingUtil.base64Decode(key);

String signature = System.encodingUtil.base64Encode(
Crypto.sign('RSA-SHA256', Blob.valueOf(jwtRequest), 
privateKey)).replace('+', '-').replace('/', '_');



I have tried python code but this is not working

import hmac,hashlib
from base64 import b64encode, b64decode 
res = hmac.new(input_key,message, digestmod=hashlib.sha256).hexdigest()


Please help


-- 
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/1f1ccf2a-b4b9-4494-a90a-fb9e34604d32%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to use RSA-SHA256 in python using private key

2018-08-05 Thread prakash sharma
Hi all,
I am stuck while salesforce jwt-bearer auth.
I need help in this code section:

String key='x';

Blob privateKey = EncodingUtil.base64Decode(key);

String signature = System.encodingUtil.base64Encode(
Crypto.sign('RSA-SHA256', Blob.valueOf(jwtRequest), 
privateKey)).replace('+', '-').replace('/', '_');



I have tried python code but this is not working

import hmac,hashlib
from base64 import b64encode, b64decode 
res = hmac.new(input_key,message, digestmod=hashlib.sha256).hexdigest()


Please help


-- 
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/51f39a5a-de7d-4cfd-a14c-f8424b08fa0f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Channels/Redis fault tolerance with Twemproxy?

2018-08-05 Thread Tim Nelson
For sure, in order to support haproxy/redis-sentinel asgi_redis would have
to handle redis-py's   ReadOnlyError and reopen the connection. Way above
my pay grade to inject this into 1.X.  It seems 2.X might suffer from the
same issue as I don't see it handling this condition either.  Still baffles
me no one is using some for of fault-tolerant Redis in production yet.
Surely others must have been bitten by this already.

I'll have to weigh the merits (and pain) of migrating to Channels 2 this
late in the game, we don't have many consumers, but we do some funky things
with session data since we are multi-tenant.


On Sun, Aug 5, 2018 at 2:53 PM Andrew Godwin  wrote:

> Channels 1 and its Redis bindings have different behaviours to 2, so this
> might be improved there (but I can't guarantee it).
>
> Andrew
>
> On Sun, Aug 5, 2018 at 11:48 AM Filbert  wrote:
>
>> Wow, I thought I had this working using haproxy in front of
>> redis-sentinel.  haproxy fails over when redis-sentinel fails over within
>> 30 seconds.
>>
>> Problem is Daphne (Channels 1.X), reports over and over:
>>
>> Error trying to receive messages: Error running script (call to
>> f_3640886a0c8901ca9188f5f7a5f7a346145b9c5f): @user_script:3: @user_script:
>> 3: -READONLY You can't write against a read only slave.
>>
>>
>> Which I assume means Daphne doesn't detect a problem and just keeps the
>> socket open on the (old) master that is now the slave.
>>
>>
>> On Thursday, August 2, 2018 at 8:53:24 PM UTC-4, Andrew Godwin wrote:
>>>
>>> Yup, any sort of TCP-level proxy with failover will work for this sort
>>> of thing, but you'll likely see some errors whenever you failover as
>>> Channels loses its blocking connection that it's using to wait for messages
>>> - as always, please test a failover before you rely on it!
>>>
>>> Andrew
>>>
>>> On Thu, Aug 2, 2018 at 5:50 PM Filbert  wrote:
>>>
 Andrew,
 Just to be clear, there is no reason I can't use haproxy to front end
 redis sentinel to effectively hide all this from channels 1 or 2 right?
 Very surprised there isn't anyone running this in production that doesn't
 need some form of HA.  Buried trying to get a product out the door right
 now, but as I get time and more familiar with channels I'll probably dig in
 deeper on this.
 Thanks.

 On Thursday, August 2, 2018 at 7:32:52 PM UTC-4, Andrew Godwin wrote:
>
> The Sentinel option was removed in the 2.0 rewrite as it didn't have
> someone to help maintain it (I didn't have the time then and don't right
> now), so you are right, there's currently no easy HA option for Redis with
> Channels.
>
> If you're interested in one, I can give you some tips on what code
> needs to be written, but it's not something I really want to maintain
> myself as part of the greater Channels effort as HA solutions tend to be
> quite workload-heavy to develop and test and end up being specific to
> certain deployment scenarios. Contributions of code that could help are
> welcome, though.
>
> Andrew
>
> On Wed, Aug 1, 2018 at 1:22 PM Filbert  wrote:
>
>> Well in digging through posts I see Sentinel may be an option, does
>> that mean if my CHANNEL_LAYER would have a single host entry?
>>
>> On Wednesday, August 1, 2018 at 9:42:39 AM UTC-4, Filbert wrote:
>>>
>>> Thanks Andrew,
>>> So with a load-balanced ten web server implementation using Channels
>>> (and of course ten instances of redis) do I have a HA solution then?  
>>> RIght
>>> now Django settings simply has a list of those servers in 
>>> CHANNEL_LAYERS,
>>> what if (say) three of them crash, will Channels continue to try and 
>>> hash
>>> to the dead servers? Again, I'll accept a brief set of errors, but if 
>>> this
>>> effectively causes Channels to continue to error that is not my 
>>> definition
>>> of HA.
>>> Thanks.
>>>
>>> On Sunday, July 22, 2018 at 8:09:16 PM UTC-4, Andrew Godwin wrote:

 I don't think redis-cluster supports BLPOP properly still so I
 don't think you can use it.

 Andrew

 On Sun, Jul 22, 2018 at 12:46 PM Filbert  wrote:

> And just to be clear as to my options, using Channels 2.0 I can
> use Redis cluster if I have to to get failover and fault tolerance, 
> correct?
>
> On Sunday, July 22, 2018 at 12:57:22 PM UTC-4, Andrew Godwin wrote:
>>
>> I'm afraid I've never used Twemproxy, so I can't really comment
>> on it, but if you don't care about data loss, it's probably fine?
>>
>> Andrew
>>
>> On Fri, Jul 20, 2018 at 3:30 PM Filbert  wrote:
>>
>>> Going to have 10 or more EC2 instances running Channels 2.0.  I
>>> really don't want to add the complexity of Redis Cluster or Redis
>>> sentinel.  Is a decent faul

response.status 404 testing problem

2018-08-05 Thread Mike Dewhirst
I have a test which succeeds in development but fails with Apache in 
staging ...


Here is the test ...

    def test_course_view_not_found_status_code(self):
        # no course exists with pk of 99
    response = self.client.get(reverse('course:course_view', 
kwargs={'pk': 99}))

    self.assertEquals(response.status_code, 404)

The status code from the staging server with Apache is 301  <-- Huh?

The test class tearDown() deletes all courses between each test.

Here is the view ...

def course_view(request, pk=None):
    course = get_object_or_404(Course, pk=pk)
    # login is needed if there are questions/answers
    if course.login_needed or request.user.is_authenticated:
    return course_login_required(request, course=course)
    else:
    return course_login_not_required(request, course=course)

What am I doing wrong?

Thanks

Mike

--
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/dff00ca5-ef30-85ed-dc6a-96d06db988d9%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: response.status 404 testing problem

2018-08-05 Thread Mike Dewhirst

Forgot to mention ...

dev = Django 1.11.15, Python 3.6 and 2.7 on Windows 10
staging = Django 1.11.15, Python 2.7 on Ubuntu 16.04 (no GUI) Apache 2.4

Sorry

Mike

On 6/08/2018 1:44 PM, Mike Dewhirst wrote:
I have a test which succeeds in development but fails with Apache in 
staging ...


Here is the test ...

    def test_course_view_not_found_status_code(self):
        # no course exists with pk of 99
    response = self.client.get(reverse('course:course_view', 
kwargs={'pk': 99}))

    self.assertEquals(response.status_code, 404)

The status code from the staging server with Apache is 301  <-- Huh?

The test class tearDown() deletes all courses between each test.

Here is the view ...

def course_view(request, pk=None):
    course = get_object_or_404(Course, pk=pk)
    # login is needed if there are questions/answers
    if course.login_needed or request.user.is_authenticated:
    return course_login_required(request, course=course)
    else:
    return course_login_not_required(request, course=course)

What am I doing wrong?

Thanks

Mike



--
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/dd876785-ecba-2a99-cf1f-676dabdeda08%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.