Adding language to url of an already multilingual site

2015-06-10 Thread Linux4Bene
Hi,


I created a multi lingual site in Django 1.7.1 where the user can change 
the language by means of a dropdown menu at the top of the site.
The urls are www.site.com/page. The page view checks the language, and 
then loads the correct templates which are named the same as the page.
The template is in a directory of its own and to find it, I only need to 
do this: template = 'template_subdir/{}.html'.format(page)

This works great but might be a bit less useful when trying to refer 
people to an url in a different language.
To that end I've created an additional function that first checks for a 
language in the url, then calls the original page function.

urls.py:
...
url(r'^(?P.*)/(?P[-\w\d]+)$', 
'main.views.page_lang',name='page_lang'),
url(r'^(?P[-\w\d]+)$', 'main.views.page',name='page'),
...

views.py
def page_lang(request, language, thepage):
# Set the language
check_for_language(language)
activate(language)
request.session['django_language'] = language

# Next load the page
return page(request, thepage)

def page(request, page):
...

This allows reconstruction of the url but only the current page. If you 
click another page, the language is still changed but the language is not 
added to the url as expected. There are a couple of questions remaining:

- When dealing with multilingual sites, is it better to deal with an url 
with or without the language or both? Without makes the url shorter and 
clean, with makes it more accessible. I'm leaning toward the latter.

- I thought of using language prefix but the prefix argument to 
i18_patterns() is deprecated in v1.8 and I'm not going to add a feature I 
know is changing in the near future. There is a reference to 
django.conf.urls.url() but it's not clear to me on how the proceed with 
this to add the language part in front of my url's.

Thanks for any info regarding this matter,

Regards,
Benedict




-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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/ml8oaf%24ukb%241%40ger.gmane.org.
For more options, visit https://groups.google.com/d/optout.


Re: Installing Django and Python 3.4 on a freshly registered Debian VPS

2015-07-07 Thread Linux4Bene
Op Sat, 04 Jul 2015 19:39:00 +0200, schreef Andreas Kuhne:


> Hi,
> 
> Just searching the net I found:
> http://www.extellisys.com/articles/python-on-debian-wheezy . It has
> information about how to install python 3.4 on debian. However I haven't
> used Debian myself (we use ubuntu on our production servers), so I can't
> verify if it's completely correct. Looks ok though. If possible switch
> to an ubuntu server instead, because then you will get python 3.4 as
> standard.
> 
> Regarding apache, I would probably choose nginx instead because it
> should be faster.
> 
> Regards,
> 
> Andréas

That's how I do it on my VPS. I also compile my own version.
Another option on Debian might be to look for a back port of Python 3.4
depending on the version (Wheezy 7.8/Jessie 8.1) you run.
Wheeze has python 3.2; Jessie Python 3.4, both installable as:

  apt-get install python3

You can find what packages debian uses in the various releases:

https://packages.debian.org/ 

I like to compile my own as I works perfectly with virtualenv to exactly 
use the version I want for my projects without messing with the system 
wide Python installation.

Regards,
Bene

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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/mngj7k%24kmo%245%40ger.gmane.org.
For more options, visit https://groups.google.com/d/optout.