2014-11-04 14:18 GMT+01:00 Sudipta Sen <[email protected]>:
>
>
> ---------- Forwarded message ---------
> From: Sudipta Sen <[email protected]>
> Date: Tue Nov 04 2014 at 6:46:17 PM
> Subject: Global Variable
> To: <[email protected]>
>
>
> Hi folks,
>
> I am very new to django and facing some problems.
>
> 1. I need a global variable, which I can use throughout the application.
> Like let's say base_url.
>
> - I tried defining one variable in settings and using it places like
> this
> - from django.conf import settings
> - url = settings.BASE_URL+'login'
> - This gives me an error : non-keyword arg after keyword arg
> - Also this process seems to be painful, every time I have to import
> settings in each of my views.
>
> 2. I need a custome context variable to be passed everytime.
>
> - I tried this: in the same directory where my settings is, I created
> a context_processors.py
> - context_processors.py:
> - def baseurl(request):
> - return {"base_url" : "/some/url/"}
> - In my settings.py file I am adding this line :
> -
>
> TEMPLATE_CONTEXT_PROCESSORS += ('context_processors.baseurl',)
>
> -
>
> This gives me an error : NameError: name 'TEMPLATE_CONTEXT_PROCESSORS'
> is not defined
>
>
> Please help me on these issues.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAO0Um5FCybTFF9BeJn%3DTw755EFsCVhL8TEw14pjQTxnP5muwtA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAO0Um5FCybTFF9BeJn%3DTw755EFsCVhL8TEw14pjQTxnP5muwtA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
Hi Sudipta,
You can do this in one of 2 ways:
1. Add it to your settings file, like you have done. I would however write
: url = "%s/login" % settings.BASE_URL instead.
2. Add a context processor. You should in your settings.py add:
TEMPLATE_CONTEXT_PROCESSORS = (
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.static",
"django.core.context_processors.tz",
"django.contrib.messages.context_processors.messages",
"django.core.context_processors.request",
"context_processors.baseurl",
)
That includes the normally added context processors (at least those that we
have in our project at the moment).
Regards,
Andréas
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CALXYUb%3DmhKbCwppZfaCurW6nc%3DBkJ6-aB2v14UrLoxjq4Zx%3DQw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.