I wish to have multiple django installations. One at / (which is working fine) and one at /adam. The one at slash adam is redirected by apache correctly, until you try and visit an app. E.g. /admin works but /adam/admin does not work. I get the error:
Page not found (404)
Request Method: GET
Request URL: http://[CENSORED]/adam/
Using the URLconf defined in bms.urls, Django tried these URL patterns, in this order:
^admin/doc/
^admin/
The current URL, , didn't match any of these.
Notice the empty commas. The apache virtual host is:
<VirtualHost *:80>
ServerName [CENSORED]
DocumentRoot /home/user/bms
Alias /static/admin/ /usr/local/lib/python2.7/site-packages/Django-1.3-py2.7.egg/django/contrib/admin/media/
<Directory /home/user/bms/apache>
Order allow,deny
Allow from all
</Directory>
<Directory /home/ajt1g09/bms/apache>
Order allow,deny
Allow from all
</Directory>
WSGIDaemonProcess bms user=user group=user processes=2 threads=25 python-path=/usr/local/lib/python2.7/site-packages
WSGIProcessGroup bms
WSGIScriptAliasMatch ^/adam(.*) /home/ajt1g09/bms/apache/django.wsgi
WSGIScriptAlias / /home/user/bms/apache/django.wsgi
</VirtualHost>
And the django.wsgi file in ajt1g09/bms/apache:
import os
import sys
path = '/home/ajt1g09/bms'
if path not in sys.path:
sys.path.append(path)
sys.path.append('/usr/local/lib/python2.7/site-packages')
sys.path.append('/home/ajt1g09')
os.environ['DJANGO_SETTINGS_MODULE'] = 'bms.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
And finally, the urls.py file in ajt1g09/bms (clearly showing /admin is there):
from django.conf.urls.defaults import
patterns, include, url
#Uncomment the next two lines to enable the admin: from django.contrib
import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'bms.views.home', name='home'),
# url(r'^bms/', include('bms.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)), )
I have no idea what the problem is.
You shouldn't be using:
WSGIScriptAliasMatch ^/adam(.*) /home/ajt1g09/bms/apache/django.wsgi
Just use:
WSGIScriptAlias /adam /home/ajt1g09/bms/apache/django.wsgi
The WSGIScriptAliasMatch will not work as written because you haven't re substituted the matched part from back into last argument. Ie.,
WSGIScriptAliasMatch ^/adam(.*) /home/ajt1g09/bms/apache/django.wsgi$1
You should though simply not be using WSGIScriptAliasMatch. That is for advanced use cases only and requires you be very careful in using it because how you use it can impact what SCRIPT_NAME/PATH_INFO are set to when passed to application and it is those that urls.py matching is based off.
Related
I'm developing a django website and am currently working on deploying. I'm following this tutorial. And im in the last stage of the tutorial (1:08:00 in the video). After he finished configuration th django-project.conf file he saves and everything is working, but me on the other hand, i get an:
Not Found
The requested URL / was not found on this server.
Apache/2.4.34 (Ubuntu) Server at **** Port 80
This is my projects .conf file:
<VirtualHost *:80>
ServerName _
Redirect 404 /
Alias /static /home/user/project/static
<Directory /home/user/project/static>
Require all granted
</Directory>
<Directory /home/user/project/project>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIScriptAlias / /home/user/project/project/wsgi.py
WSGIDaemonProcess project_app python-path=/home/user/project python-home=/home/user/project/venv
WSGIProcessGroup project_app
</VirtualHost>
This is my urls.py:
from django.contrib import admin
from django.urls import path, include
from . import views
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.homepage),
path('rh/', views.rh, name="rh"),
path('gvt/', views.gvt, name="gvt"),
path('fth/', views.fth, name="fth"),
path('pages/', include('pages.urls')),
]
This is my wsgi.py
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'excelsite.settings')
application = get_wsgi_application()
sys.path.append('/home/alexholst/excelsite')
This is the error.log
(Couldnt copy, so i have this screenshot instead)
here
I'm trying to do the Django tutorial. Part 1 went OK (i.stack.imgur.com/US5GN.jpg)
However, once I activate the admin site the root I get (i.stack.imgur.com/EXfE4.jpg). Edit (as S.O. doesn't yet allow me to post images; thanks, cberner):
Page not found (404)
Request Method: GET
Request URL: http://dj1.net/
Using the URLconf defined in dj1_net.urls, Django tried these URL patterns, in this order:
^admin/
The current URL, , didn't match any of these.
dj1.net is my test domain (editing /etc/hosts), and while dj1.net/admin/ now works as expected, I don't know why dj1.net/ throws this error once I uncomment (as instructed) the line
url(r'^admin/', include(admin.site.urls)),
under mysite/urls.py (in my case dj1_net/urls.py). It seems to me everything should work as before unless the GET request is against /admin/.
My stack: a Debian 6.0 VPS with Apache and mod_wsgi. I want to avoid Django's built-in server: if I can't deploy it for real, I'd rather know earlier rather than later. In fact, for easy PHP support I'm very interested in an Apache-based solution.
For further reference, here is my /etc/apache2/sites-available/dj1.net:
<VirtualHost *:80>
ServerName dj1.net
DocumentRoot /var/www/dj1_net
Alias /static/ /var/www/dj1_net/static/
Alias /media/ /var/www/dj1_net/media/
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
WSGIScriptAlias / /var/www/dj1_net/django.wsgi
WSGIProcessGroup dj1_net
WSGIDaemonProcess dj1_net processes=2 threads=16 maximum-requests=1000 display-name=apache-dj1_net-wsgi
</VirtualHost>
Finally, here is /var/www/dj1_net/django.wsgi:
import sys
import os
import os.path
sys.path.append(os.path.dirname(__file__))
os.environ['DJANGO_SETTINGS_MODULE'] = 'dj1_net.settings'
from django.core.handlers.wsgi import WSGIHandler
application = WSGIHandler()
Just to be upfront, I know close to nil about Apache server configuration and WSGI. I do, however, want to make this set-up work before embarking in Django. I followed a mix of the official instructions and this post, since I frankly couldn't make get Django to work applying either instructions verbatim. I'm afraid the bottom of the problem must lie there...
Any tips will be greatly appreciated.
Cheers!
S.P.
Second edit. Here is dj1_net/urls.py (thanks, scytale):
from django.conf.urls import patterns, include, url
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'dj1_net.views.home', name='home'),
# url(r'^dj1_net/', include('dj1_net.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
)
You don't have a url defined for the root of your site. You'll need to add one, for example:
url(r'^$', 'dj1_net.views.my_view_function'),
That would go after the line that defines the admin URL.
I'm in the process of moving a django site over to a new server. On the old server, the django site was accessed like mysite.com/ , but now, we would like to access it via mysite.com/mysite, and let mysite.com handle something else. I have made the following changes to apache like so:
WSGIDaemonProcess mysite processes=2 threads=15 display-name=%{GROUP}
WSGIProcessGroup mysite
WSGIScriptAlias /mysite /srv/www/django.wsgi
#WSGIScriptAlias /mysite /srv/www/django.wsgi #previous config
<Directory /srv/www/mysite/mysite >
Order allow,deny
Allow from all
</Directory>
Alias /site_media "/srv/www/mysite/site_media/"
Alias /admin_media "/srv/www/mysite/admin_media/"
This seems to work fine- pointing the browser at mysite.com/unity/admin allows me to access the admin page correctly, and view the respective apps correct. However, anything that uses a custom template seems to be half-baked. For instance, there's an entry in a template below like so:
{% ifcodable cl.model %}<li>Coding Report</li>{% endifcodable %}
This will redirect the page to
http://mysite.com/report/texas/texas
As opposed to
http://mysite.com/mysite/report/texas/texas
I'm not sure if the template is set up incorrectly or if it has something to do with the new alias. My urls.py looks like so:
from django.conf.urls.defaults import *
from django.conf import settings
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
.....
(r'^report/([a-zA-Z]+?)/([a-zA-Z]+?)/(overall|\d+)/{0,1}$', 'mysite.k.views.performance'),
(r'^report/(.+?)/(.+?)/{0,1}$', 'mysite.k.views.report'),
.....
My django.wsgi file looks like so:
import os,sys
sys.path.append('/srv/www/mysite')
sys.path.append('/srv/www/mysite/mysite')
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..')
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
I don't know what the proper thing would be to do to correct the problem. I'm fairly new to django, so if there is a wicked simple solution I apologize. Any advice would be greatly appreciated!
The problem is that your url begins with /report in the href attribute. Beginning with a / means that it should be relative to the root of your domain. I believe what you need to change is how the Django sites framework is configured, and it looks like this question has the answer.
Also, you should probably use the url tag in your templates instead of hardcoding the urls in your anchor tags.
I am trying to deploy my django project which is located at home/doga/headend/ and just to run it on the localhost (will be a LAN accessable project). My main problem is that I can use the site well however the /admin/ folder is giving me Internal Server Error error.
anyway here is my etc/apache2/sites-available/default file
<VirtualHost *:80>
ServerName /
ServerAlias */
DocumentRoot /home/doga/headend/
LogLevel warn
WSGIScriptAlias / /home/doga/headend/apache/django.wsgi
Alias /media /home/doga/headend/media/statics
Alias /admin_media /usr/lib/python2.4/site-packages/django/contrib/admin/media
</VirtualHost>
and here is my home/doga/headend/apache/django.wsgi file
import os, sys
import django.core.handlers.wsgi
sys.path.append('/home/doga/')
sys.path.append('/home/doga/headend')
os.environ['DJANGO_SETTINGS_MODULE'] = 'headend.settings'
application = django.core.handlers.wsgi.WSGIHandler()
lastly my main url.py
from django.conf.urls.defaults import *
from django.conf import settings
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Example:
# (r'^headend/', include('headend.foo.urls')),
# Uncomment the admin/doc line below and add 'django.contrib.admindocs'
# to INSTALLED_APPS to enable admin documentation:
(r'^table/(?P<pid>.*)/$', 'main.views.table_view'),
(r'^graph/(?P<pid>.*)/$', 'main.views.graph_view'),
(r'^graph/$', 'main.views.platform_graph_view'),
(r'^table/$', 'main.views.platform_view'),
(r'^csv/$', 'main.views.csv_view'),
(r'^recent/$', 'main.views.recent_view'),
(r'^$', 'main.views.main_view'),
(r'^cs/(?P<number>.*)/$', 'main.views.ch_view'),
#(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
(r'^admin/', include(admin.site.urls)),
#(r'^$', 'main.views.main_view'),
#(r'^media/(?P<path>.*)$', 'django.views.static.serve',
# {'document_root': '/home/uluc/headendmedia/statics'}),
)
I don't believe you should be setting the DocumentRoot to /home/doga/headend. Won't this give access to all your source code?
What detail does the Apache log give for the Internal Server Error?
Below are the relevant configuration files, also at http://dpaste.com/97213/ .
The apache config is currently working, because accessing 'example.com/' shows me the index.html file I have placed at the document root.
I'd like to serve Django/apps at the prefix '/d', so 'example.com/d/' would load the default app, 'example.com/d/app3' would load another, as configured in urls.py.
Serving Django, I'm using the suggested mod_wsgi, on Linux.
Currently, I can access the Ticket app at 'example.com/d', but when the #login_required decorator tries to send me to the login page, I get sent to 'example.com/accounts/login', rather than the expected 'example.com/d/accounts/login'.
Since the default app loads correctly, I'm not sure what I'm doing wrong here, or if this is a bug in Django when generating the urls.
Any suggestions?
EDIT:
As a note, if I change the apache config line:
WSGIScriptAlias /d /home/blah/django_projects/Tickets/apache/django.wsgi
to
WSGIScriptAlias / /home/blah/django_projects/Tickets/apache/django.wsgi
The application, commenting, and logging in all work fine. Even going to 'example.com/admin' loads the admin, although I've left the admin media broken, so no stylesheets are loaded.
--- Configs Follow:
#
# /home/blah/django_projects/Ticket/urls.py
#
from django.conf.urls.defaults import *
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^', include('ticket.urls')),
(r'^admin/', include(admin.site.urls)),
(r'^comments/', include('django.contrib.comments.urls')),
)
#
# /home/blah/django_projects/Ticket/apache/django.wsgi
#
import os, sys
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..')
sys.path.append('/home/blah/django_projects')
sys.path.append('/home/blah/django_projects/Tickets')
os.environ['DJANGO_SETTINGS_MODULE'] = 'Tickets.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
#
# /etc/apache2/sites-available/django_tickets_wsgi (apache conf)
#
NameVirtualHost *
<VirtualHost *>
Alias /media /home/blah/django_projects/Tickets/media
WSGIScriptAlias /d /home/blah/django_projects/Tickets/apache/django.wsgi
WSGIDaemonProcess exmaple_com user=blah group=blah processes=1 threads=10
WSGIProcessGroup example_com
ServerAdmin localhost#example.com
ServerName example.com
DocumentRoot /var/www/
<Directory /var/www/>
Options -Indexes FollowSymLinks -MultiViews -Includes
AllowOverride None
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
ServerSignature Off
</VirtualHost>
This is a possible duplicate of Django Apache Redirect Problem, as that answer solved this problem.
I only eventually stumbled on that answer by opening almost all of the 'related questions' here, just out of desperation. From my perspective, I think my question has some valuable "search friendly" words.
EDIT: The answer: (via alex vasi)
Things to try:
Change current domain to "yourdomain.tld/cflow" in the "sites" framework. It's easy to do using django admin or dumpdata/loaddata manage.py commands.
Looks like your site is using login_required decorator. In that particular case you can add to settings.py:
LOGIN_URL = '/[prefix]/accounts/login/'
In your urls.py rename urlpatterns to base_urlpatterns; then add the followinig definition at the end of the same file:
urlpatterns = patterns('',
'^', include(base_urlpatterns), # iff you wish to maintain the un-prefixed URL's too
'^your_prefix/', include(base_urlpatterns),
)