What is reverse()?

reverse() | Django documentation Let’s suppose that in your urls.py you have defined this: url(r’^foo$’, some_view, name=”url_name”), In a template you can then refer to this url as: <!– django <= 1.4 –> <a href=”{% url url_name %}”>link which calls some_view</a> <!– django >= 1.5 or with {% load url from future %} in your … Read more

Setting DEBUG = False causes 500 Error

Django 1.5 introduced the allowed hosts setting that is required for security reasons. A settings file created with Django 1.5 has this new section which you need to add: # Hosts/domain names that are valid for this site; required if DEBUG is False # See https://docs.djangoproject.com/en/1.9/ref/settings/#allowed-hosts ALLOWED_HOSTS = [] Add your host here like [‘www.beta800.net’] … Read more

When saving, how can you check if a field has changed?

Essentially, you want to override the __init__ method of models.Model so that you keep a copy of the original value. This makes it so that you don’t have to do another DB lookup (which is always a good thing). class Person(models.Model): name = models.CharField() __original_name = None def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.__original_name = … Read more

How to get the current URL within a Django template?

Django 1.9 and above: ## template {{ request.path }} # -without GET parameters {{ request.get_full_path }} # – with GET parameters Old: ## settings.py TEMPLATE_CONTEXT_PROCESSORS = ( ‘django.core.context_processors.request’, ) ## views.py from django.template import * def home(request): return render_to_response(‘home.html’, {}, context_instance=RequestContext(request)) ## template {{ request.path }}

(13: Permission denied) while connecting to upstream:[nginx]

Disclaimer Make sure there are no security implications for your use-case before running this. Answer I had a similar issue getting Fedora 20, Nginx, Node.js, and Ghost (blog) to work. It turns out my issue was due to SELinux. This should solve the problem: setsebool -P httpd_can_network_connect 1 Details I checked for errors in the … Read more

Can I access constants in settings.py from templates in Django?

If it’s a value you’d like to have for every request & template, using a context processor is more appropriate. Here’s how: Make a context_processors.py file in your app directory. Let’s say I want to have the ADMIN_PREFIX_VALUE value in every context: from django.conf import settings # import the settings file def admin_media(request): # return … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)