Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Why Django for Web Development

1,244 views

Published on

Why Django for Web Development?

Published in: Education, Technology
  • salam agha reza
    kheili mamnoon az slidehatoon....
    mishe lotf konid begid amoozeshe django ham midi ya na?
    mamnoon
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

Why Django for Web Development

  1. 1. OutLine… • What is Django? • Django ad MVC Desing pattern • Django Architecture • Why Django for Web Development • Steps to create new project • What Django generates • Sample Application
  2. 2. What is Django? • “Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design”
  3. 3. Django ad MVC Desing pattern • MVT Architecture: Models:Describes your data structure/database schema Views:Controls What a user sees Templates:How a user sees it Controller:The Django framework – URL Parsing
  4. 4. Django Architecture
  5. 5. Why Django for Web Development • Lets you divide code modules into logical groups to make it flexible to change…MVT design pattern • Provides auto generate web admin to ease the website administration • Provides pre-packaged API for common user tasks • Provide your template system to define Html template for your web pages to avoid code duplication • Allows you to define what URL be for a given function • Everything is in python (schema/settings)
  6. 6. Steps to create New Project  Create a project  Start an application  Create the database (MySQL, Postgresql, SQLite)  Define DB Settings in Settings.py  Define your models  Add pluggable modules  Write your templates  Define your views  Create URL mapping  Test Application  Deploy Application (Linux, Apache, mod_Python, DB)
  7. 7. What Django generates mysite/ manage.py mysite/ django-admin.py startproject mysite __init__.py settings.py urls.py wsgi.py polls/ __init__.py admin.py python manage.py startapp blog migrations/ __init__.py models.py tests.py views.py Create a project Start an application
  8. 8. blog/models.py file so it looks like this: class Post(models.Model): title = models.CharField(max_length=100,unique=True) slug = models.SlugField(max_length=100,unique=True) content = HTMLField() created = models.DateTimeField(db_index=True) meta_desc = models.CharField(max_length=150,blank=True) author = models.ForeignKey(User) category = models.ForeignKey('Category') published = models.BooleanField(default=False) tags = TaggableManager() def __unicode__(self): return "%s" % self.title def get_absolute_url(self): return reverse('showpost',args=[str(self.category.slug),str(self.slug)])
  9. 9. blog/views.py file so it looks like this: def main(request): """Main listing.""" posts = Post.objects.all().order_by("-created") paginator = Paginator(posts, 4) try: page = int(request.GET.get("page", '1')) except ValueError: page = 1 try: posts = paginator.page(page) except (InvalidPage, EmptyPage): posts = paginator.page(paginator.num_pages) return render_to_response("postlist.html", dict(posts=posts, user=request.user)) class IndexView(ListView): queryset = Post.objects.filter(published=True).order_by('-created')
  10. 10. Thanks! life is short - you need Python! @py_Django @Morteza Dariushi

×