Django, nginx, gunicorn: why on some page gives Server Error (500)?

FireGM

Not at all, but selectively.

For example function random_video does not work, and video_list works. settings.py

import os
from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS, AUTHENTICATION_BACKENDS

BASE_DIR = os.path.dirname(os.path.dirname(__file__))
TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]

SECRET_KEY = 'secret'

DEBUG = False

TEMPLATE_DEBUG = False

ALLOWED_HOSTS = ['.mydomain.ru']

INSTALLED_APPS = ('django.contrib.admin',
                  'django.contrib.auth',
                  'django.contrib.contenttypes',
                  'django.contrib.sessions',
                  'django.contrib.messages',
                  'django.contrib.staticfiles',
                  'django.contrib.sites',
                  'django_youtube',
                  'gdata',
                  'south',
                  'index',
                  'loginza',
                  'users',
                  'embed_video',
                  'for_parse',
                  'taggit',
                  'gunicorn',
)

SITE_ID = 1

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
)

ROOT_URLCONF = 'myproject.urls'

WSGI_APPLICATION = 'myproject.wsgi.application'

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'mydatabase',
        'USER': 'myuser',
        'PASSWORD': 'mypassword',
        'HOST': 'localhost',  # Set to empty string for localhost.
        'PORT': '',  # Set to empty string for default.
    }
}


SOUTH_MIGRATION_MODULES = {
    'taggit': 'taggit.south_migrations',
}

LANGUAGE_CODE = 'ru-ru'

TIME_ZONE = 'Europe/Moscow'

USE_I18N = True

USE_L10N = True

USE_TZ = True

STATIC_URL = '/static/'
STATIC_ROOT = '/home/myuser/projects/myproject/static/'

LOGGING = {
    'version': 1,
    'disable_existing_loggers': True,
}

urls.py

from django.conf.urls import patterns, url, include

urlpatterns = patterns('myapp.views',
    # list of the videos
    url(r'^videos/$', 'video_list', name="myapp_video_list"),
    #random video
    url(r'^random/$', 'random_video', name='random_video'),
)

views.py

def video_list(request):
    videos_list = Video.objects.all()
    paginator = Paginator(videos_list, 42)
    page = request.GET.get('page')
    try:
        videos = paginator.page(page)
    except PageNotAnInteger:
        videos = paginator.page(1)
    except EmptyPage:
        videos = paginator.page(paginator.num_pages)

    return render_to_response(
        "django_youtube/videos.html",
        {"videos": videos},
        context_instance=RequestContext(request),
    )

def random_video(request):
    all_video = Video.objects.count()
    video11 = Video.objects.all()[random.randint(0, all_video)]
    video_params = _video_params(request, video11.video_id)
    video_params['video'] = video11
    video11.views += 1
    video11.save(update_fields=['views'])
    return render_to_response(
        "django_youtube/video.html",
        video_params,
        context_instance=RequestContext(request)
    )

logs the error in nginx for my project.

[08/Sep/2014:17:15:04 -0400] "GET /youtube/random/ HTTP/1.1" 500 38 "http://mydomain.ru/video/eQIaa3dVKjc/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/37.0.2062.94 Chrome/37.0.2062.94 Safari/537.36"

The rest did not give out. Domain and other things replaced. If you need more detail - write please.

FireGM

Well, when I learn to check my code ??? The mistake was that he tried to get non-existent video! Randint function gives a figure inclusive.

all_video = Video.objects.count () 
video11 = Video.objects.all () [random.randint (0, all_video)] 

And if it was non-existent video, then everything crash and had to issue an error. But I do not have to handle the error page, so nginx issued his usual 500.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Commiting new changes to Gunicorn + Nginx + Django dockerized application in server

From Dev

500 Internal Server Error page in MVC

From Dev

Error Logging in Nginx+Gunicorn+Supervisor+Django

From Dev

.htaccess file gives 500 internal server error

From Dev

Django/Wagtail some images upload error 500

From Dev

Django+Gunicorn+nginx Internal Server Error, where is the error and how to fix it?

From Dev

nginx 500 Internal Server Error

From Dev

Creating symlink gives 500 Internal Server Error

From Dev

NLTK+TextBlob in flask/nginx/gunicorn on Ubuntu 500 error

From Dev

URL resolution error using Gunicorn, Nginx, and Django

From Dev

Bad Request (400) and 502 error: Nginx, gunicorn, django

From Dev

Internal Server 500 Error - Django

From Dev

NginX 500 (Internal Server) Error

From Dev

CURL gives 500 Internal server error

From Dev

External IP error on Django + Nginx + Gunicorn setup

From Dev

500 internal server error when deploy django with gunicorn and nginx

From Dev

Django with gunicorn and nginx: HTTP 500 not appearing in log files

From Dev

Jupyer lab gives Error 500: Internal Server Error

From Dev

nginx and gunicorn for a django project

From Dev

nginx 500 Internal Server Error

From Dev

Creating symlink gives 500 Internal Server Error

From Dev

Bad Request (400) and 502 error: Nginx, gunicorn, django

From Dev

PHP MySql insert gives server error 500

From Dev

External IP error on Django + Nginx + Gunicorn setup

From Dev

Ajax call to webmethod gives ERROR 500 Internal server error

From Dev

Multiple Django app using nginx and gunicorn on Ubuntu 14.04 trusty server

From Dev

After hosting to server symfony gives 500 internal server error

From Dev

deploy laravel on server with nginx get a 500 error

From Dev

Django Deployment with nginx - gunicorn from another server

Related Related

  1. 1

    Commiting new changes to Gunicorn + Nginx + Django dockerized application in server

  2. 2

    500 Internal Server Error page in MVC

  3. 3

    Error Logging in Nginx+Gunicorn+Supervisor+Django

  4. 4

    .htaccess file gives 500 internal server error

  5. 5

    Django/Wagtail some images upload error 500

  6. 6

    Django+Gunicorn+nginx Internal Server Error, where is the error and how to fix it?

  7. 7

    nginx 500 Internal Server Error

  8. 8

    Creating symlink gives 500 Internal Server Error

  9. 9

    NLTK+TextBlob in flask/nginx/gunicorn on Ubuntu 500 error

  10. 10

    URL resolution error using Gunicorn, Nginx, and Django

  11. 11

    Bad Request (400) and 502 error: Nginx, gunicorn, django

  12. 12

    Internal Server 500 Error - Django

  13. 13

    NginX 500 (Internal Server) Error

  14. 14

    CURL gives 500 Internal server error

  15. 15

    External IP error on Django + Nginx + Gunicorn setup

  16. 16

    500 internal server error when deploy django with gunicorn and nginx

  17. 17

    Django with gunicorn and nginx: HTTP 500 not appearing in log files

  18. 18

    Jupyer lab gives Error 500: Internal Server Error

  19. 19

    nginx and gunicorn for a django project

  20. 20

    nginx 500 Internal Server Error

  21. 21

    Creating symlink gives 500 Internal Server Error

  22. 22

    Bad Request (400) and 502 error: Nginx, gunicorn, django

  23. 23

    PHP MySql insert gives server error 500

  24. 24

    External IP error on Django + Nginx + Gunicorn setup

  25. 25

    Ajax call to webmethod gives ERROR 500 Internal server error

  26. 26

    Multiple Django app using nginx and gunicorn on Ubuntu 14.04 trusty server

  27. 27

    After hosting to server symfony gives 500 internal server error

  28. 28

    deploy laravel on server with nginx get a 500 error

  29. 29

    Django Deployment with nginx - gunicorn from another server

HotTag

Archive