10 Oct 2013

Make existing project as a github repository

Recently i was working on side project on Django and then decided to put it on the github.
First of all you need to create a repository on github with same name as folder you want to put on git.
Then follow following steps :

Step 1: >> git init

Step 2: >> git add .

Step 3: >> git commit -m "setup commit"
               above command will print list of all files.

Step 4:  >>git remote add origin https://github.com/username/reponame.git

Step 5 : >> git push origin master

       if error :
                  To https://github.com/navyad/pollsite.git  ! [rejected]        master -> master (non-fast-forward) error: failed to push some refs to 'https://github.com/navyad/pollsite.git' To prevent you from losing history, non-fast-forward updates were rejected Merge the remote changes (e.g. 'git pull') before pushing again.  See the 'Note about fast-forwards' section of 'git push --help' for details.
       then :
              >> git pull origin master
       
Step 6: >>git push origin master
       

Its done , you can check the git repo.

Custom HTTP 404 error page in Django

Django default HTTP 404 error page looks like this , provided in DEBUG=True in settings.py file.
Following error message is fine for the development , but when you are going for production then you need lot better than that.



In following steps describes how can you serve your custom 404.html page for HTTP 404 error.

Step 1: Create a 404.html file having your error message.

Step 2 : Place 404.html in directory pointed by TEMPLATE_DIRS .

Step 3: In urls.py set handler404 = 'app.views.custom_404'. this will be a you custom view which will return the 404.html page when Http 404 error occurs.

Step 4: Create you custom view in views.py , 
          def custom_404(request):
                    return render_to_response('404.html')

Step: 5 in settings.pyALLOWED_HOSTS = ['hostname'],  this will be a IP address from which you are running the django project.

Step 6: very important , in settings.py , make DEBUG=False, Only then you will able to see the custom error page.


Hope that now you will easily able to see you custom error page.