django tutorial: custom 404 and 500 views - http-status-code-404

Windows 7
Python 2.7.3
Django 1.5
python manage.py runserver
I am following the tutorial as available at 'https://docs.djangoproject.com/en/1.5/intro/tutorial03/'
I got as far as the 'Write a 404 (page not found) view' before things got wierd.
I have tried to work out how to make a custom 404 view. However, I am not sure:
A. Where exactly the custom 404.html file should reside. Should it be in my project directory tree or in my Django directory tree. My project directory tree looks like this,
1> mysite
2> - mysite
3> - polls
4> - templates
5> - polls
6> - templates
7> - admin
Currently the 404.html is # 6>
B. What modifications have to be made where? I understand that a handler404 and a handler500 need to be set in the 'root' url conf. I have a url.py residing # 2> and 3> (see tree above). Assuming that 2> is the correct place I assume that the syntax is as follows,
handler404 = 'templates.404'
handler500 = 'templates.500'
What else needs to be set, where?

As I can see you have a little mistake, but dont worry.
Look, try this:
handler404 = 'mysite.views.error404'
Then in mysite (the second mysite) creates a views.py if you dont have. In that views.py put:
from django.shortcuts import render
def error404(request):
return render(request,'404.html')
and thats all! In templates, create that file and do something nice!
Remember that only works in production (DEBUG=False) otherwise django use the traceback.
Is the same for 505, and you maybe can try handler404 = 'polls.views.see404' and put in the views.py then but you know, tastes are different hehehe.
Now, try something else, for example: comment in the urls.py
#handler404 = 'mysite.views.error404'
and remove too in the views.py the def.
In the index of your templates file creates a simple 404.html.
Run the server in production and produce that 404 error, what happened?

Related

DSpace error with oai import

After configuring my DSpace server, its working correctly but when I look at the OAI identify page (http://repositorio.puce.edu.ec/oai/request?verb=Identify) so we can be harvested, it says that the repository is localhost instead of my URL. I investigated and found out that to update this, I have to run this command: dspace/bin/dspace oai import -c but when I run that command is gives me the following error: Solr server (http://repositorio.puce.edu.ec/solr/oai) is down, turn it on.
I can see the Solr Admin (it can't be seen from the outside because of security reasons) so I don't know what should be turned on or how to do it?
Thanks for the help.
I encountered this error in the past.
Looking at my oai.cfg file, I used localhost for some settings and my public URL for others.
solr.url=http://localhost/solr/oai
# OAI persistent identifier prefix.
# Format - oai:PREFIX:HANDLE
identifier.prefix = repository.library.georgetown.edu
# Base url for bitstreams
bitstream.baseUrl = https://repository.library.georgetown.edu
If you need to make a config change, be sure to clear the cache after restarting service.

cakephp - apache - turn off directory browing of tmp folder

It seems cake's tmp folder is browse-able (if you go to localhost/tmp it shows all the files I put there), how can I turn this off without breaking anything?
I tried adding .hacccess file to that folder with - Options -Indexes - didn't work
I tried adding index.html - didn't work.
I am afraid to mess with the apache config files because it was a nightmare to get cake & php and everything working properly....
Why would cake have this on by default, isnt it a security issue? (at least the scan tool my client ran flagged it).
thanks
Joel
Something is definitely wrong with your setup that has nothing to do with CakePHP. Your webroot (localhost) should be at this location: app/webroot and the tmp should be at app/tmp. In order for you do access http://localhost/tmp, tmp would have to be at app/webroot/tmp or you are redirecting it, which is not how CakePHP is designed to be setup.

Server giving 404 not found

I am deploying a spring application which contains files with around 100000 entries. Each row in the file has about 23 chars.
The app deploys fine when a file has 100000 entries but when I increase the contents to 400000 entries, when I access my app url I get a 404 Not found error.
I need to figure out what causes the crash ( whether a memory problem or something else ) but I do not see anything erroneous in the tomcat log files, using the command vmc files [app_name] tomcat/logs/catalina.... just info messages related to server startup.
Are there other options to debug the issue?
Thanks,
Cristian
I would look into what Dan has mentioned! Also can you look at the logs folder to see if the files there give more information.
vmc logs <app-name>
or
vmc files <app-name> logs/stderr.log
vmc files <app-name> logs/stdout.log
Okay, the application was using too much memory, as a result the Java processes was being destroyed causing the router to return a 404 when trying to route to the application.

Migrating GAE app from python 2.5 to 2.7

I am trying to migrate my app and everything worked fine until I changed in app.yaml
from threadsafe: false to threadsafe: true.
The error I was receiving was:
threadsafe cannot be enabled with CGI handler: a/b/xyz.app
After some googling I found:
Only scripts in the top-level directory work as handlers, so if you have any in subdirectories, they'll need to be moved, and the script reference changed accordingly:
- url: /whatever
# This doesn't work ...
# script: lib/some_library/handler.app
# ... this does work
script: handler.app
Is there any workaround for this(if above research is valid), as I don't want to change my project hirarchy?
You can have your handlers anywhere as long as it's a valid python import path.
My app.yaml is full of entries like
- url: /_ah/queue/deferred
script: google.appengine.ext.deferred.application
login: admin
The folders need __init__.py in them to make them work as modules, but you can usually replace any / with .
Alternatively do as Daniel suggest, and note that you'll probably have to mangle the sys.path first to include lib dir and then import handler.
Put a main file in the top-level directory and import all your handlers there, then reference them via that file

access static file in public_html/tmp without going trough controller in cakephp

I have uploaded my cakephp app to cpanel and adjust and configure it to works with cpanel. Everything mostly works, however i find out that try to retrieve static file from tmp in public_html result in error. It tries to go to controller i think.
My structure is like this :
/cakephp139
/cake
/vendors
/renttycoons <= this is app folder
/public_html
/tmp
/js
....
I tried to access www.domain.com/tmp/test.csv, but result in errors although the test.csv was there. This is the error :
Error: The requested address '/403.shtml' was not found on this server.
Any idea would be appreciated. Thanks
does it gives you cake like error? it seems like a permission error.
erorr 403 is forbidden error, not a not found or something like that. Your server gives you that error and tries to show you a page for that error that is not found so you are receiving a 404 for not having a page for a 403 error hehe.
It must be a permission error, try changing permission to 705 in the temp folder, your test.csv file included. If you are creating it with php, php normally creates them with the minimun permission, at least that happened to me... you may use chmod function in php to change the permissions after creating a file.

Resources