这是我设置的DigitalOcean Droplet的错误:
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 %}
错误不会在本地发生。我看到关键字是一个空字符串,所以我去shell调查。
>>> from deals.models import Vendor
>>> vendor_qs = Vendor.objects.all()
>>> for item in vendor_qs: print item.slug
...
my-first-vendor
my-second-vendor
>>>
以下是我试图访问的网页的型号,视图和网址:
...
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
...
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)
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
)
同样,100%的代码完全可以在本地找到。我花了大约10个小时进行故障排除,我无法弄清楚......
值得注意的是:test_type视图工作得很好(只是输出其他模型的子类的测试视图),而todays_deals不起作用。它返回:
render_to_string() got an unexpected keyword argument 'context'
它的观点如下: 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})
我很困惑。甚至&#p;冻结&#39;这些环境之间是一样的......
答案 0 :(得分:0)
更新
问题是nginx配置中的单个正斜杠。
配置的静态部分应该是&#39; / static&#39;不是&#39; / static /&#39;