django - I am attempting to add two models from separate local apps into one template -
i trying access content content.models , post post.models in blog.html template. idea content able edit text on site through django admin.
the directory stucture follows:
- src [folder] - content [folder] - migrations [folder] - __init__.py - admin.py - apps.py - models.py - tests.py - views.py - main [folder] - settings [folder] - __init__.py - base.py - migrations [folder] - __init__.py - db.sqlite3 - models.py - urls.py - views.py - wsgi.py - posts [folder] - migrations [folder] - templatetags [folder] - __init__.py - admin.py - apps.py - forms.py - models.py - tests.py - urls.py - utils.py - views.py - templates - base.html - blogbase.html views.py - main looks follows:
from django.shortcuts import render django.http import httpresponse django.views.generic import view django.views.generic.base import templateview, templateresponsemixin, contextmixin # posts.models import post, content # app.models import * posts.models import post content.models import content class dashboardtemplateview(templateview): template_name = "base.html" context_object_name = 'name' def get_context_data(self, *args, **kwargs): context = super(dashboardtemplateview,self).get_context_data(*args, **kwargs) context["title"] = "this us" return context class myview(contextmixin, templateresponsemixin, view): def get(self, request, *args, **kwargs): context = self.get_context_data(**kwargs) context = {'content_list' : content.objects.all(), 'post_list':post.objects.all()} return self.render_to_response(context) my models.py - main follows:
from django.db import models post.models import post context.models import contest my urls.py - main follows:
from django.conf import settings django.conf.urls import include, url django.conf.urls.static import static django.contrib import admin django.db import models django.views.generic import listview accounts.views import (login_view, register_view, logout_view) # views import * urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^comments/', include("comments.urls", namespace='comments')), url(r'^register/', register_view, name='register'), url(r'^login/', login_view, name='login'), url(r'^logout/', logout_view, name='logout'), url(r'^', include("posts.urls", namespace='posts')), # line below not work # url(r'^', dashboardtemplateview.as_view(template_name=('base.html')), name='name'), ] if settings.debug: urlpatterns += static(settings.static_url, document_root=settings.static_root) urlpatterns += static(settings.media_url, document_root=settings.media_root) when add in line doesn't work
url(r'^', dashboardtemplateview.as_view(template_name=('base.html')), name='name'), to url patterns following error
file "blog/src/main/urls.py", line 39, in url(r'^', dashboardtemplateview.as_view(template_name=('base.html')), name='name'), nameerror: name 'dashboardtemplateview' not defined
i using django 1.9 , python 2.7
Comments
Post a Comment