Django /admin/ Page not found (404)
<p>I have the following error:</p>

<pre><code>Page not found (404)
Request Method:     GET
Request URL:    http://127.0.0.1:8000/admin/
Raised by:  nw.views.post_detail
</code></pre>

<p>But I can enter in example to <a href="http://127.0.0.1:8000/admin/nw/" rel="nofollow">http://127.0.0.1:8000/admin/nw/</a></p>

<p>And if I remove all post_detail functions/parts of the code then I can enter to <a href="http://127.0.0.1:8000/admin/" rel="nofollow">http://127.0.0.1:8000/admin/</a> and it works, so something with this post_detail is wrong.</p>

<p><strong>nw.views.post_detail:</strong></p>

<pre><code>def post_detail(request, slug=None):
    instance = get_object_or_404(Post, slug=slug)

    context = {
        "instance": instance,
    }
    return render(request, "post_detail.html", context)
</code></pre>

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

<pre><code>urlpatterns = [
    url(r'', include('nw.urls', namespace='posts')),
    url(r'^admin/', admin.site.urls),
]
</code></pre>

<p>and</p>

<pre><code>urlpatterns = [
    url(r'^$', post_list, name='list'),
    url(r'^create/$', post_create),
    url(r'^(?P&lt;slug&gt;[\w-]+)/$', post_detail, name='detail'),
    url(r'^(?P&lt;slug&gt;[\w-]+)/edit/$', post_update, name='update'),
    url(r'^(?P&lt;slug&gt;[\w-]+)/delete/$', post_delete),
]
</code></pre>

<p><strong>post_detail.html:</strong></p>

<pre><code>{% extends 'base.html' %}

{% block head_title %}{{ instance.title }} | {{ block.super }}{% endblock head_title %}

{% block content %}
    &lt;div class="instance"&gt;
        &lt;h1&gt;{{ instance.title }}&lt;/h1&gt;
        &lt;div class="date"&gt;{{ instance.published }}&lt;/div&gt;
        &lt;p&gt;{{ instance.text|linebreaksbr }}&lt;/p&gt;

        &lt;a href="https://www.facebook.com/sharer/sharer.php?u={{ request.build_absolute_uri }}"&gt;
        Facebook
        &lt;/a&gt;

        &lt;a href="https://twitter.com/home?status={{ share_string }}%20{{ request.build_absolute_uri }}"&gt;
        Twitter
        &lt;/a&gt;

        &lt;a href='https://plus.google.com/share?url={{ request.build_absolute_uri }}'&gt;google&lt;/a&gt;


        &lt;a href="https://www.linkedin.com/shareArticle?mini=true&amp;url={{ request.build_absolute_uri }}&amp;title={{ instance.title }}&amp;summary={{ share_string }}&amp;source={{ request.build_absolute_uri }}"&gt;
        Linkedin
        &lt;/a&gt;

        &lt;a href="http://www.reddit.com/submit?url={{ request.build_absolute_uri }}&amp;title={{ share_string }}."&gt;Reddit&lt;/a&gt;

    &lt;/div&gt;

{% endblock %}
</code></pre>

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

<pre><code>class Post(models.Model):
    author = models.ForeignKey('auth.User', default=1)
    title = models.CharField(max_length=200)
    slug = models.SlugField(unique=True)
    text = models.TextField()
    published = models.DateTimeField(auto_now=False, auto_now_add=True)
    updated = models.DateTimeField(auto_now=True, auto_now_add=False)

    def __str__(self):
        return self.title

    def get_absolute_url(self):
        return reverse("posts:detail", kwargs={"slug": self.slug})

    class Meta:
        ordering = ["-published"]


def create_slug(instance, new_slug=None):
    slug = slugify(instance.title)
    if new_slug is not None:
        slug = new_slug
    qs = Post.objects.filter(slug=slug).order_by("-id")
    exists = qs.exists()
    if exists:
        new_slug = "%s-%s" %(slug, qs.first().id)
        return create_slug(instance, new_slug=new_slug)
    return slug


def pre_save_post_receiver(sender, instance, *args, **kwargs):
    if not instance.slug:
        instance.slug = create_slug(instance)


pre_save.connect(pre_save_post_receiver, sender=Post)
</code></pre>

<p>In your case this route working <code>url(r'^(?P&lt;slug&gt;[\w-]+)/$', post_detail, name='detail'),</code> and this function called <code>instance = get_object_or_404(Post, slug=slug)</code></p>

<p>You can replace route like this</p>

<pre><code>urlpatterns = [
  url(r'^admin/', admin.site.urls),
  url(r'', include('nw.urls', namespace='posts')),
]
</code></pre>

<p><strong>The order of route is important</strong></p>

python django