Abdul Hamid
Abdul Hamid

Reputation: 208

how to work with two apps in django

Hello im learning django and i would like to know if its a way to make my two apps work i have my folders like this

mysite/
--/app1 (blog app)
--/app2  (a list of users that signs up with a form)
--/mysite
--db
--manage.py

my app2 has the index.html and the structure.html which i use to inheritate my others html files, so im trying to use the post_list.html file that i made in my app1, first of all this is how my urls looks something like this

from django.conf.urls import patterns, include, url
from django.contrib import admin

admin.autodiscover()

urlpatterns = patterns('',

    url(r'^admin/', include(admin.site.urls)),
    url(r'info', 'app2.views.grid'),
    url(r'', 'app2.views.home'),
    url(r'^blog/', 'app1.views.post_list')
)

my app1 views looks like this

from django.shortcuts import render
from .models import Post
# Create your views here.

def post_list(request):
    posts = Post.objects.filter(published_date_isnull=False).order_by('published_date')
    return render(request, 'app1/post_list.html',{'posts':posts})

then my post_list.html looks like this

{% extends "/app2/templates/app2/structure.html" %}

{% block content %}
    {% for post in posts %}
        <div class="post">
            <div class="date">
                {{ post.published_date }}
            </div>
            <h1><a href="">{{ post.title }}</a></h1>
            <p>{{ post.text|linebreaks }}</p>
        </div>
    {% endfor %}

{% endblock %}

when i enter to my browser and type 127.0.0.1:8000/blog/ it keeps apearing my app2/index.html, what am i missing? do i have to do anything else than adding my views to my url like i did?

aditional info: i added my app2 and my app1 to my settings thoe

Upvotes: 0

Views: 80

Answers (1)

generalpiston
generalpiston

Reputation: 891

I think your urls.py needs to be updated:

urlpatterns = patterns('',
    url(r'^admin/', include(admin.site.urls)),
    url(r'^info', 'app2.views.grid'),
    url(r'^$', 'app2.views.home'),
    url(r'^blog/', 'app1.views.post_list')
)

url(r'', 'app2.views.home') will act like a wild card since python uses regular expressions to match. Take a look at the URL dispatcher documentation for a better understanding of what's going on.

Upvotes: 1

Related Questions