简体   繁体   中英

Django app functions locally, breaks when deployed to DigitalOcean

This is the error on the DigitalOcean droplet I set up:

Django Error (line 38 is highlighted)

Reverse for 'vendor' with arguments '()' and keyword arguments '{u'vendor': u''}' not found. 1 pattern(s) tried: [u'deals/vendor/(?P<vendor>[\\w-]+)$']
...
34                {% if vendors %}
35                  <li class="divider"></li>
36                  <li class="dropdown-header">By Vendor</li>
37                  {% for vendor_item in vendors|slice:"0:3" %}
38                    <li><a href={% url 'deals:vendor' vendor=vendor_item.slug %}>{{ vendor_item.name }}</a></li>
39                  {% endfor %}
40                {% endif %}

The error does not occur locally. I see that the keyword is an empty string, so I went to the shell to investigate.

>>> from deals.models import Vendor
>>> vendor_qs = Vendor.objects.all()
>>> for item in vendor_qs: print item.slug
...
my-first-vendor
my-second-vendor
>>>

Here is the model, view, and url for the page I'm trying to reach:

models.py

...
class Vendor(models.Model):
    name = models.CharField(max_length=200)
    slug = models.CharField(max_length=200, blank=True)
    url = models.CharField(max_length=200, blank=True)
    location = models.CharField(max_length=200, blank=True, null=True)
    shipping = models.BooleanField(blank=True)
    img = models.ImageField(blank=True)

    def __str__(self):
        return self.name

views.py

...
def index(request, data=None): 
if data is None:
    data = {}

vendors = Vendor.objects.annotate(Count('deal')) \
    .order_by('name')
data['vendors'] = vendors

categories = Category.objects.annotate(Count('deal')) \
    .exclude(deal__count__lt = 40) \
    .order_by('name')
data['categories'] = categories

return render(request, 'deals/_index.html', data)

urls.py

urlpatterns = patterns('',
    # Examples:
    url(r'^$', views.index, name='index' ),
    url(r'vendor/(?P<vendor>[\w-]+)$', views.get_deals_by_vendor, name='vendor'),
    url(r'test_type/$', views.view_model_subclass_by_deal), # Remove in production
    url(r'todays_deals/$', views.view_deals_updated_today), # Remove in production
    )

Again, 100% of this code works totally find locally. I've spent ~10 hours troubleshooting and I can't figure it out...

Of note: the test_type view works just fine (just a test view that outputs the subclasses of other models), while the todays_deals does not function. It returns:

render_to_string() got an unexpected keyword argument 'context'

and it's view looks like: def view_deals_updated_today(request): today = date.today()

    todays_deals = Deal.objects \
        .filter(updated_at__gte = today) \
        .exclude(created_at__lte = today) \
        .select_subclasses()

    return render_to_response('test/deal_list.html', context = {'todays_deals':todays_deals})

I'm quite confused. Even 'pip freeze' is the same between these environments...

Update:

The issue was a single forward slash in the nginx config.

the static portion of the config should be '/static' not '/static/'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM