How can I create a new url in a Django app?
<p>I have implemented a model in a Django app and I would like add an url to handle the view for this model. </p>

<pre><code>class Post(models.Model):
     author = models.ForeignKey('auth.User')
     title = models.CharField(max_length=200)
     text = models.TextField()
     created_date = models.DateTimeField(default=timezone.now)
     published_date = models.DateTimeField(blank=True, null=True)
</code></pre>

<p>Can you help me?</p>

<p>I would recommend the Django tutorial as well: <a href="https://docs.djangoproject.com/en/1.10/intro/tutorial01/" rel="nofollow">https://docs.djangoproject.com/en/1.10/intro/tutorial01/</a></p>

<p>However, to answer your question, you could do a setup like this:</p>

<p><strong>views.py:</strong></p>

<pre><code>from django.shortcuts import render
from .models import Post

def my_view(request):
    posts = Post.objects.all()
    return render(request, 'template.html', {'posts': posts})
</code></pre>

<p><strong>urls.py:</strong></p>

<pre><code>from django.conf.urls import url
from . import views

urlpatterns = [
    url(r'^$', views.my_view, name='my_view')
]
</code></pre>

python django url view