I have uploaded my Django site on a development server at Digital Ocean and started serving it using apache2 and mod_wsgi. I am also using apache2 to serve static content. It's a fresh installation of Debian on the server, and have done minimal changes.
I am using Django Haystack and Solr to support full-text search. I've checked that both the database and Solr are kept up to date.
Now, if the url I use to retrieve a page contains a query string (it can be as small a ?asd
, where asd
is not a valid param) everything comes out fine.
If however it does not contain such a query string, I get a version of the page that can be several hours (days?) old, even containing items I've deleted from the database.
The issue is resolved as soon as I restart apache2.
Doing apache2ctl -M | grep cache
returns nothing, and settings.py
does not reference caching either. Anyone have an idea what could be the cause of this?
Update: my view is a standard search view:
class SearchView(SearchView):
form_class = ArticleSearchForm
template_name = 'articles/index.html'
paginate_by = 5
def get_queryset(self):
queryset = super(SearchView, self).get_queryset()
return queryset
def get_context_data(self, *args, **kwargs):
context = super(SearchView, self).get_context_data(*args, **kwargs)
context['ctx'] = context
context['articles'] = map(lambda o: o.object, context['object_list'])
return context
And the associated search form:
class ArticleSearchForm(SearchForm):
start_date = forms.DateField(required=False, widget=forms.DateInput(attrs={ 'id': 'start_date', 'class': 'form-control' }))
end_date = forms.DateField(required=False, widget=forms.DateInput(attrs={ 'id': 'end_date', 'class': 'form-control'}))
def __init__(self, *args, **kwargs):
super(ArticleSearchForm, self).__init__(*args, **kwargs)
self.fields['q'].widget.attrs['class'] = 'form-control'
def search(self):
sqs = super(ArticleSearchForm, self).search()
if not self.is_valid():
return self.no_query_found()
if not self.cleaned_data.get('q'):
sqs = self.searchqueryset.all()
if self.cleaned_data['start_date']:
sqs = sqs.filter(pub_date__gte=self.cleaned_data['start_date'])
if self.cleaned_data['end_date']:
sqs = sqs.filter(pub_date__lte=self.cleaned_data['end_date']+datetime.timedelta(days=1))
return sqs
But considering the page I get is inconsistent with what's in the database, I don't think my code gets called at all.
Update 2: It's weirder than this. Sometimes upon hitting refresh on my browser I get correct results. Hitting refresh again a couple of times I get incorrect results again. I tried wgetting the page on the server (via localhost) and I get incorrect results.