M
M
MaximPatrushev2020-01-16 22:34:00
Django
MaximPatrushev, 2020-01-16 22:34:00

The code does not work only on the server, what could be the reason?

There is a django site with pretty simple routing, this is what the root urls.py looks like :

from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    path('', include('pages.urls')),
    path('services/', include('services.urls')),
    path('bookings/', include('bookings.urls')),
    path('admin/', admin.site.urls),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

This is how urls.py for services looks like :
from django.urls import path

from . import views

urlpatterns = [
  path('', views.index, name='services'),
  path('<int:service_id>', views.service, name='service'),
]

And views.py for services :
from django.shortcuts import render, get_object_or_404

from .models import Service


def index(request):
    services = Service.objects.all()

    context = {
        'services': services
    }

    return render(request, 'services.html', context)


def service(request, service_id):
    services = Service.objects.all()
    service = get_object_or_404(Service, pk=service_id)

    context = {
        'services': services,
        'service': service
    }

    return render(request, 'service.html', context)

This is how the link to the services page in the template looks like:
<a href="{% url 'services' %}" class="nav-link">Услуги</a>

On localhost, everything works correctly, on the server, the page with services gives a 500 error. Moreover, only this one - path('', views.index, name='services') , the page with one service path('', views.service, name='service') works correctly.
The django version is 2.2.1 both on the local and on the server, on the ubuntu server 18.04. What could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MaximPatrushev, 2020-01-18
@MaximPatrushev

One of the images used on this page was not uploaded correctly to the server.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question