def say_hello(name):
print 'Hello,', name
def say_goodbye(name):
print 'Bye,', name
phrases = {
'hello': say_hello,
'bye': say_goodbye,
}
def say(what, name):
phrases[what](name)
say('hello', 'Ivan')
say('bye', 'Oleg')
server {
listen 80 default_server;
return 404;
}
server {
listen 80;
server_name example.com www.example.com;
...
}
is_voted = user in question.voted_users.all()
is_voted = question.voted_users.filter(pk=user.pk).exists()
voted = request.POST['choice']
voted_choice = get_object_or_404(Choice, pk=voted)
There is no magic rule for setting the number of processes or threads to use. It is very much application and system dependent. Simple math like processes = 2 * cpucores will not be enough. You need to experiment with various setups and be prepared to constantly monitor your apps. uwsgitop could be a great tool to find the best values.
__init__
, куда параметром отдавайте нужное.class WorkForm(forms.Form)
road = forms.ModelChoicField(label='', queryset=Road.objects.none())
def __init__(self, *args, **kwargs):
user_id = kwargs.pop('user_id', None)
super(WorkForm, self).__init__(*args, **kwargs)
self.fields['road'].queryset = Roads.objects.filter(contractor=user_id)