Forums

Nav bar works locally but not on Pythonanywhere

Hi everyone,

as one can tell from my username I created a recipe application to store recipes. The navigation bar has a home tab where you can see all recipes and then there are other tabs dedicated to different categories such as salads, pasta, desserts and so on. I included "category" in my Django recipe model, so that the respective recipes are shown when you click on different tabs. When I run the application on localhost this works perfectly fine: I see all recipes on the home tab, pasta recipes on the pasta tab, and desserts on the desserts tab.

However, I've now deployed my application and I only see recipes on the home site. When I click on the pasta tab or the desserts tab then there's nothing there (even though I already created pasta and dessert recipes). I have no idea why this is happening and there are no errors that give me a hint what to do or where to look.

This is the code for my Django model:

from django.db import models
from django.urls import reverse
from ckeditor.fields import RichTextField

#Category Dropdown
CATEGORY_CHOICES = (
    ('salads','SALADS'),
    ('soups', 'SOUPS'),
    ('dough','DOUGH'),
    ('pasta','PASTA'),
    ('rice','RICE'),
    ('meats','MEATS'),
    ('fish','FISH'),
    ('spreads','SPREADS'),
    ('sweets','SWEETS'),
)

# Create your models here.
class Recipe(models.Model):
    title = models.CharField(max_length=100)
    category = models.CharField(max_length=100, choices=CATEGORY_CHOICES, default='Add your category here')
    ingredients = RichTextField(default='Add your ingredients here')
    description = RichTextField(default='Add your description here')
    picture = RichTextField(blank=True, null=True)

def get_absolute_url(self):
    return reverse("recipes-detail", kwargs={"pk": self.pk})

def __str__(self):
    return self.title

My "Home" template:

{% extends 'recipes/base.html' %}

{% block content %}
    <h1>Recipes App Home</h1>
    {% for recipe in recipes %}
      <div class="card my-4" style="width: 18rem; float:left; margin:10px">
        <div class="card-body">
          <h5 class="card-title">{{ recipe.title }}</h5>
          <h6 class="card-subtitle mb-2 text-muted">{{ recipe.updated_at|date:"F d, Y" }}</h6>
          <p>{{ recipe.picture|safe }}</p>
          <p class="card-text">{{ recipe.ingredients|safe }}</p>
          <a href="{% url 'recipes-detail' recipe.pk %}" class="card-link">View Recipe</a>
        </div>
      </div>
    {% endfor %}
    {% endblock content %}

And the "Pasta" template:

{% extends 'recipes/base.html' %}

{% block content %}
    <h1>Pasta</h1>
    {% for recipe in recipes %}
    {% if recipe.category == "Pasta" %}
      <div class="card my-4" style="width: 18rem; float:left; margin:10px">
        <div class="card-body">
          <h5 class="card-title">{{ recipe.title }}</h5>
          <h6 class="card-subtitle mb-2 text-muted">{{ recipe.updated_at|date:"F d, Y" }}</h6>
          <p>{{ recipe.picture|safe }}</p>
          <p class="card-text">{{ recipe.ingredients|safe }}</p>
          <a href="{% url 'recipes-detail' recipe.pk %}" class="card-link">View Recipe</a>
        </div>
      </div>
    {% endif %}
    {% endfor %}
    {% endblock content %}

Does someone more experienced than me immediately see a mistake? Or maybe someone can point me to some things I could check out to see why this is happening.

Thanks in advance

There's nothing immediately obvious to me, unfortunately :-(

Which database are you using to store the recipes -- MySQL or SQLite? If it's SQLite, could you share your DATABASES config from the settings.py file?

Oh too bad, but thank you anyway for looking! I'm using the normal SQLite database, this is my config from the settings file:

# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}

Do you have any other settings files that could be used instead? What if you try to access your data form Django shell?