Posts

Free courses make you a full stack developer

Start with Python Python is a widely used high-level programming language for general-purpose programming, created by Guido van Rossum and first released in 1991. An interpreted language, Python has a design philosophy which emphasizes code readability (notably using whitespace indentation to delimit code blocks rather than curly brackets or keywords), and a syntax which allows programmers to express concepts in fewer lines of code than possible in languages such as C++ or Java. The language provides constructs intended to enable writing clear programs on both a small and large scale. Python features a dynamic type system and automatic memory management and supports multiple programming paradigms, including object-oriented, imperative, functional programming, and procedural styles. It has a large and comprehensive standard library. Python interpreters are available for many operating systems, allowing Python code to run on a wide variety of systems. CPython, the reference

Python Mechanize Cheat Sheet

Image
Mechanize Create a browser object Create a browser object and give it some optional settings. import mechanize br = mechanize.Browser() br.set_all_readonly(False)    # allow everything to be written to br.set_handle_robots(False)   # ignore robots br.set_handle_refresh(False)  # can sometimes hang without this br.addheaders =         # [('User-agent', 'Firefox')] Open a webpage Open a webpage and inspect its contents response = br.open(url) print response.read()      # the text of the page response1 = br.response()  # get the response again print response1.read()     # can apply lxml.html.fromstring() Using forms List the forms that are in the page for form in br.forms():     print "Form name:", form.name     print form To go on the mechanize browser object must have a form selected br.select_form("form1")         # works when form has a name br.form = list(br.forms())[0]  # use when form is unnamed Using Contro

Python mechanize For Browsing

Image
How to install Mechanize we can install mechanize in two ways  Using pip : pip install mechanize Or download the mechanize distribution,open it and run it: python setup.py install  Browsing with Mechanize  Here is an example on how to browse webpage in python program   import mechanize   br = mechanize.Browser()   br.open("http://www.example.com/") Follow second link with element text matching regular expression response1 = br.follow_link(text_regex=r"cheese\s*shop",nr=1) assert br.viewing_html()   print br.title()   print response1.geturl()   print response1.info() # headers   print response1.read() # body To get the response code from a website, you can the response.code   from mechanize import Browser   browser = Browser()   response = browser.open('http://www.google.com')   print response.code Get all forms from a website   import mechanize   br = mechanize.Browser() br.open("http://www.google.com/")  

Rich text editor in Django

Image
M any people often want What You See Is What You Get (WYSIWYG) editors when creating content from within their web applications. This can be either in the Django admin control panel or for the end user. One of the most flexible and useful of the WYSIWYG editors currently available is TinyMCE due to its extensive plugin library and robust feature set. Integration with Django is relatively simple given that you extend the functionality of built in classes. The first thing we will need to do is create a custom widget from forms.Textarea found in the django.forms module. We accomplish this by inheriting the Textarea class and overriding the constructor and render methods. Defining the relative path (on your web server) to the TInyMCE javascript source is also required here. So be aware that you will need to change that path to suite your environment. You may also want to change the content_css variable to include your sites’ main CSS file. The following is the source code for widgets.py

Usefull django packages

Image
There are many reasons why I like developing web applications with Python and Django but the main one is the awesome community and projects around the language and framework. Every time I search for something there’s always a Django or Python project available to make my life easier. Here’s an   incomplete   list of Python and django related projects that I have used or I’m planning to test. This might help someone starting out to get an idea of how awesome is to work with this technologies. Django Debug Toolbar https://github.com/dcramer/django-debug-toolbar The Django Debug Toolbar is a configurable set of panels that display various debug information about the current request/response and when clicked, display more details about the panel’s content. South http://south.aeracode.org South brings migrations to Django applications. Its main objectives are to provide a simple, stable and database-independent migration layer to prevent all the hassle schema changes over

SEO tips for django

Image
Use the redirects app to manage url changes  Django documentation Use post save signals to handle slug/url changes in your models  Link Use sitemap  The sitemap framework Use slugfield  Model field reference Use cached template loaders to reduce page load times  The Django template language: For Python programmers Use a css/js compressor to reduce page load times  django_compressor Use django-robots to manage your robots file  django-robots If you’re rolling an e-commerce site, don’t reinvent the wheel, just go with  The Best Django CMS . It’s the best code and seo friendly cms framework for django Manage object level meta data with  django-seo Not django specific but submit your site to google webmasters  Webmasters – Google . For bing:  Bing – Webmaster Tools Not django specific again but load your page using  Make the Web Faster  and make all the recommended changes Crawl your site content to find br

Editor TinyMCE in Django admin

Image
  Let stepwise Make the   download of TinyMCE Create folder structure template Configure   TEMPLATE_DIRS   in   settings.py   of your project (   example below   ) Edit the urls.py Edit admin.py Create configuration file TinyMCE  1. Download TinyMCE   you can download tinymce from http://www.tinymce.com/download/download.php 2.   Structure The folder structure is something like: project app templates css js tinymce     Place the folder inside tinymce   project> templates> js   , as shown above. 3.   TEMPLATE_DIRS (settings.py) Edit the   settings.py   and edit / add these lines: import the . path   TEMPLATE_DIRS = ( the . path . join ( the . path . dirname ( __file__ ) , 'templates' ) , ) 4.   Serving static files Open the file   urls.py   (the project root) and add the line 3 as below: urlpatterns = patterns ( '' , ... ( r '^ js / (? <path> P. *) $' ,