I have a question about my django settings
and nginx
in order to display a download link receives in an email generated by a Django view.
1- Context
The emailing part works fine. I can receive this one. In this email I created a link which let to download a file stored in MEDIA
folder.
My issue is about the url generated in the email which works with localhost, but not on my testing environment.
2- My code in my local environment
In order to build my download link, I pick up the protocol
and domain
through :
url = self.request.build_absolute_uri(reverse('home'))
Then, in my message, I created a link like this :
<a href="{{ url }}{% url '<my app>:export_download' token=token %}">Download link to your export file</a>
In local, it gives me :
http://localhost:8000//download_export/<my_file>/
As you can see, I have a double slashes in my generated url which makes an error. I solved this issue with :
url = request.build_absolute_uri('/').strip("/")
The urls.py file looks like this :
urlpatterns = [
url(r'^home$', HomeView.as_view(), name='home'),
...
url(r'^download_export/(?P<token>.*)/$', ExportDownloadView.as_view(), name='export_download'),
]
3- My code in my testing environment
In this environment, I'm using nginx as webserver. The application is available from : https://subdomain.domain.fr/dev3/<app_name>/home
The nginx.conf looks like :
location /dev3/<app_name> {
include uwsgi_params;
uwsgi_param SCRIPT_NAME /dev3/<app_name>;
uwsgi_pass unix://var/run/uwsgi/<app_name>.sock;
When I access to the generated download like sent from my testing environment, it gives me an access to :
https://subdomain.domain.fr/download_export/<my_file>
and not https://subdomain.domain.fr/dev3/<app_name>/download_export/<my_file>
It misses something ? How I can add this part /dev3/<app_name>
? By default, all other urls access to https://subdomain.domain.fr/dev3/<app_name>/something
but not my generated link.
Thank you
EDIT :
In my uwsgi.ini file, I have this both lines :
mount = /dev3/%n=main.wsgi:application
manage-script-name=true
So it should work