Django- Set created & updated date/time in your models

In Django, many of us have question how to create date time in database automatically, When a new data is inserted or Existing Data is Updated.

So, Now we can use to have the date a record was added, or most recently updated. Django makes this really easy.

class Blogs(models.Model):
    title = models.CharField(max_length=100)
    added = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)

How to Update the Current Browser URL

# UPDATE THE CURRENT URL IN BROWSER::
<script>

ChangeUrl = function(page, url) {

    if (typeof (history.pushState) != "undefined") {

        var obj = { Page: page, Url: url };

        history.pushState(obj, obj.Page, obj.Url);

        $('.breadcrumb-get-a-pro').attr('href', url);

    } else {

        alert("Browser does not support HTML5.");

    }

}

</script>

Sitemap in Python Django

Sitemap in Python Django

# For Sitemap
from django.views.generic import TemplateView
urlpatterns = [

    url(r'^admin/', admin.site.urls),

    #include testapp app url
    url(r'', include('testapp.urls')),

    url(r'^sitemap\.xml$', TemplateView.as_view(template_name='sitemap.xml', content_type='text/xml')),


]
**  keep the sitemap.xml file in app/templates/sitemap.xml