Django Apache/mod_python Admin CSS not appearing with admin tables - windows

I have Windows XP/Django/apache/mod_python working on localhost. All parts are working with the exception of the admin CSS not rendering. The admin works, but no html formatting. I've made additions in:
settings.py
INSTALLED_APPS
'django.contrib.admin',
urls.py
from django.contrib import admin
admin.autodiscover()
(r'^admin/(.*)', admin.site.root),
conf/http.conf
<Location "/">
SetHandler python-program
PythonPath "['C:/django'] + sys.path"
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
PythonDebug On
</Location>
<Location "/cpssite/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE myapplication.settings
PythonInterpreter /myapplication
PythonDebug On
</Location>
I'm stumped. Is there more code I should have added somewhere?

Does your ADMIN_MEDIA_PREFIX exist? Is it different from MEDIA_URL? Did you include the trailing slash? Is Apache handled to correctly serve up the admin media?
The default Django configuration has the admin media located at {Django install dir}/contrib/admin/media. ADMIN_MEDIA_PREFIX defaults to /media/. So you need to add something like this to your Apache config:
Alias /media/ /path/to/django/contrib/admin/media/
This will tell Apache that requests for mysite.com/media/css/whatever.css mean to serve up /path/to/django/contrib/admin/media/css/whatever.css, which should solve your issue.

I used to have the same problem and the following entry in the http.conf worked fine with me:
<Directory "Path-to-python/Lib/site-packages/django/contrib/admin/media/">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
Alias /media/ "Path-to-Python/Lib/site-packages/django/contrib/admin/media/"
<Location "/mysite/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
PythonOption django.root /mysite
PythonInterpreter mysite
PythonDebug On
PythonPath "['C:/Python/Django/apps'] + sys.path"
</Location>

Here is my django-specific apache configuration. Note, django handles every incoming url to the site (location /) except media, where it's disabled, and the data is served from django's media directory.
<Location "/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
#PythonOption django.root /
PythonDebug On
PythonPath "['e:/dj'] + sys.path"
</Location>
Alias /media e:/dj/django-trunk/django/contrib/admin/media/
<Location "/media">
SetHandler None
</Location>

If you don't want to have admin media use the /media directory, you can specify ADMIN_MEDIA_PREFIX = 'admin_media', then create a link/alias from your webserver which redirects calls to /admin_media/ to the /usr/share/pyshared/django/contrib/admin/media (depending on your OS) for your production server...

Since the question is from long time back, this may not be a relevant answer but I am putting this information to help anyone who happens to stumble here just like me.
As of version 1.4, ADMIN_MEDIA_PREFIX setting has been deprecated. The ways of serving static and media files with version >= 1.4 are described here
https://docs.djangoproject.com/en/dev/releases/1.4/#django-contrib-admin
https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/modwsgi/#serving-files
https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/modwsgi/#serving-the-admin-files
Basically it can be setup in 4 steps -
Set STATIC_ROOT to point to directory which will serve all the static files of your site
Set STATIC_URL for which static content should be served
Run manage.py collectstatic
Configure your webserver to serve requests for STATIC_URL from STATIC_ROOT
Same for media files

Related

Why Apache(centos 7) can't see route that I made?

I made route, but apache server cant see that route. There no problem with Laravel welcome page but when I try to make another folder in view. Apache cant see that page. 404 not found pop up.
Here is the Route and the Controller codes
Route::get('/pages', 'Pages#index');
and controller
function index(){
return "test";
Also my httpd my document root: /var/www/html/laravel/public
module dir:
DirectoryIndex index.html index.php
Do I need to change something else too? to make this route accessible?
in centos 7, None --to-> All makes it fine.
<Directory /var/www/html>
. . .
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None --> All
. . .
</Directory>

How to configure 2 api laravel 5.6 and a "normal" in debian

I have a Debian server 9 with Apache 2 and Laravel 5.6
I have the folder: /LcmTI/projects/www to publish my projects, port 81 answers for all projects, eg:
http://localhost: 81/project1 [html project only]
In the folder /LcmTI/projects/laravel, I have two laravel projects 5.6:
extranet at /LcmTI/projects/laravel/extranet
intranet at /LcmTI/projects/laravel/intranet
I have created a link to the two projects in the www folder (which is the folder that is published):
ln -s /LcmTI/projects/laravel/extranet/public /LcmTI/projects/www/extranet
ln -s /LcmTI/projects/laravel/intranet/public /LcmTI/projects/www/intranet
In this way, I expected without any problem to access the two laravel environments without any problem, but it is not working.
When I type:
http://localhost:81/extranet/api/test or http://localhost:81/intranet/api/test
does not work and should return:
/* file routes/api.php in both applications */
`Route::get('test', function () {
return response()-> json(['foo' => 'bar']);
});`
If I enter http://localhost:81/extranet or http://localhost:81/intranet
Enter the homepage of Laravel
My configuration for Apache 2:
<VirtualHost *:81>
DocumentRoot /LcmTI/projects/www
<Directory /LcmTI/projects/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
Require all granted
</Directory>
</VirtualHost>
I'm having a hard time setting up larval API applications on a single host.

Laravel 4 simple route not working using mod_rewrite, and .htaccess

I'm not only new to Laravel 4, but new to using frameworks. I thought I'd start with Laravel since it's gotten such good reviews.
I've got a good install of Laravel. I go to /l4/public and see the welcome page.
I'm trying to add a route to routes.php so that when I navigate to /l4/public/articles I get a response.
I get "The requested URL /l4/public/articles was not found on this server." Do I need to run an artisan command to compile the routes? It's probably something easy. Why this message?
routes.php
Route::get('/', function()
{
return View::make('hello');
});
Route::get('articles', function ()
{
//return View::make('articles');
return "Articles hello there";
});
Problem is solved by two editing changes in apache's httpd.conf file.
AllowOverride None is default. AllowOverride controls whether .htaccess files are processed.
mod_rewrite is commented out by default.
Changes to make:
Change 1: Activate mod_rewrite by uncommenting it.
Change 2:
Change
AllowOverride None
to
AllowOverride All
Now restart Apache...
The default .htaccess file that Laravel provides in the public folder specified some mod_rewrite rules. These rules were not getting applied because AllowOverride was set to none. Be sure and restart apache after changing these settings.
My configuration: Apache 2.4.6 on Windows XP.
It appears that there may be some security implications to the AllowOverride change. If anyone has additional information on this, I would like to hear it.
That Error basically say that the router cannot found your request. Make sure you already save your changes.
if you using the artisan command to running the page,just re-run again command "artisan Serve".
You need mod_rewrite on. Try: l4/public/index.php/articles
in httpd.conf change
<Directory />
AllowOverride none
Require all granted
</Directory>
to
<Directory />
AllowOverride all
Require all granted
</Directory>
then uncomment
#LoadModule rewrite_module modules/mod_rewrite.so
to
LoadModule rewrite_module modules/mod_rewrite.so

Where does RAILS_ROOT (Rails.root) come from?

I have a ruby on rails application that is located at /home/user/application. I have a Apache webserver whose DocumentRoot is /var/www. And I have a symlink /var/www/application -> /home/user/application.
My apache configuration section that concerns the ruby on rails is the following:
RailsBaseURI /application
<Directory /home/user/application>
Order Allow,Deny
Allow from all
Options -MultiViews
</Directory>
I modified the Passenger code so in the very beginning of it spawning it would print (to a file) the option app_root. If it matters, I modified the file phusion_passenger/spawn_manager.rb in the method handle_spawn_application.
The value that I get is /home/user and this is wrong, I needed /home/user/application. So my question is, how does Passenger figures out the option['app_root'] (which becomes RAILS_ROOT|Rails.Root)?
Observation: I modified the Passenger code to hardcode app_root to /home/user/application and everything worked fine.
Change the symlink so that /var/www/application points to /home/user/application/public
Then just change RailsBaseURI to RackBaseURI and undo your changes to spawn_manager.rb
Previous discussion assumed single application.
<Directory /var/www/application/public>
Order Allow,Deny
Allow from all
Options -MultiViews
</Directory>
See the Apache Phusion documentation.
You need to add DocumentRoot and append /public to your Directory config and undo your changes to spawn_manager.rb.
As you noticed, the app_root is one directory up from what is specified.. The parent directory of /home/user/application/public is /home/user/application which is the Rails root.
You want RackBaseURI instead of RailsBaseURI for Rails > 3
The reasoning behind this is so that Apache serves the static assets (which are in the public directory) and then if that isn't present Passenger routes the request to the Rails app.

Using Apache as a ruby server

Is there any way I can use Apache as a ruby server ?
You may want to consider the 'Passenger' module, see the website. Yesterday I installed this module using their instructions on the website and it went well.
I did it via gem install passenger. I have not deployed anything as yet. Good luck with whatever option you choose.
Use eruby and libapache2-mod-ruby packages then activate the ruby module with sudo a2enmod ruby.
Don't forget to create a configuration file /etc/apache/conf.d/ruby.conf and put something in here, like :
AddType text/html .rhtml
AddType text/html .rbx
DirectoryIndex index.rhtml index.rbx
<IfModule mod_ruby.c>
RubyRequire apache/ruby-run
RubyRequire apache/eruby-run
<Files *.rbx>
Options +ExecCGI
setHandler ruby-object
rubyHandler Apache::RubyRun.instance
</Files>
<Files *.rhtml>
setHandler ruby-object
rubyHandler Apache::ERubyRun.instance
</Files>
</IfModule>

Resources