django cms and zinnia skeleton override - python

I am trying to connect zinnia to django-cms 3.0
I have launched zinnia and it works just fine. Now I am trying to start changing styles. More specifically templates/zinnia/skeleton.html override.
Once I add template to override original template - url reverse starts on failing.
NoReverseMatch at /en-us/blog/
Reverse for 'entry_archive_index' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
All of the urls use namespace as in {% url 'zinnia:entry_archive_index' %} and yet reverse in shell also just fails.
What else could be done to debug it? Maybe it's because of localization?
I have urls config:
from django.conf.urls import patterns, url, include
from django.conf.urls.i18n import i18n_patterns
from django.contrib import admin
from django.conf import settings
admin.autodiscover()
urlpatterns = i18n_patterns(
'',
url(r'^admin/', include(admin.site.urls)),
url(r'^blog/', include('zinnia.urls', namespace='zinnia')),
url(r'^comments/', include('django.contrib.comments.urls')),
url(r'^tinymce/', include('tinymce.urls')),
url(r'^', include('cms.urls')),
)
if settings.DEBUG:
urlpatterns = patterns(
'',
url(r'^media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
url(r'', include('django.contrib.staticfiles.urls')),
) + urlpatterns
Settings:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.admin',
'django.contrib.sites',
'django.contrib.comments',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.contenttypes',
'my_main_django_cms_app',
'cms',
'mptt',
'menus',
'south',
'sekizai',
'djangocms_text_ckeditor',
'djangocms_picture',
'djangocms_inherit',
'djangocms_googlemap',
'cmsplugin_contact',
'tinymce',
'tagging',
'zinnia_threaded_comments',
'zinnia',
'cmsplugin_zinnia',
)
And my_main_django_cms_app structure is
.
├── cms_plugins.py
├── forms.py
├── __init__.py
├── manage.py
├── models.py
├── settings.py
├── static
├── templates
│   ├── base.html
│   ├── home.html
│   └── zinnia
│   └── skeleton.html
├── urls.py
├── wsgi.py
And my versions:
Django==1.6.5
Pillow==2.4.0
South==0.8.4
argparse==1.2.1
beautifulsoup4==4.3.2
cmsplugin-contact==1.0.0
cmsplugin-zinnia==0.6
django-app-namespace-template-loader==0.1
django-blog-zinnia==0.14.1
django-classy-tags==0.5.1
django-cms==3.0
django-mptt==0.6.0
django-reversion==1.8.1
django-sekizai==0.7
django-tagging==0.3.2
django-tinymce==1.5.2
django-xmlrpc==0.1.5
djangocms-admin-style==0.2.2
djangocms-googlemap==0.0.5
djangocms-inherit==0.0.1
djangocms-picture==0.0.2
djangocms-text-ckeditor==2.1.6
gevent==1.0.1
greenlet==0.4.2
gunicorn==19.0.0
my_main_django_cms_app==0.1
html5lib==1.0b3
ipdb==0.8
ipython==2.1.0
psycopg2==2.5
pyparsing==2.0.2
pytz==2014.4
six==1.7.2
wsgiref==0.1.2
zinnia-threaded-comments==0.2

I have been trying to integrate zinnia into django cms for a few days, and here's my experience, which gets me to the point where I can use my own django cms template for zinnia, but I'm still not getting the menus provided with cmsplugin_zinnia to work.
Compared to your setup, I've made the following changes:
Deleted zinnia namespace, so url(r'^blog/', include('zinnia.urls', namespace='zinnia')) becomes url(r'^blog/', include('zinnia.urls')).
Added app_name = 'zinnia' to cmsplugin_zinnia.cmsapp.ZinniaApphook
Moved cms after zinnia and before cmsplugin_zinnia from settings.py in demo_cmsplugin_zinnia
With this, I can select Zinnia Weblog as Application under Advanced Settings for a new Django CMS page, and give it a unique Application Instance Name as suggested in the Django CMS docs. The name of the page or its url/slug field don't matter.
From here I can come up with my own skeleton.html that makes no reference to zinnia whatsoever, and have zinnia.base.html extend my new skeleton template.
However, at this point the cmsplugin_zinnia docs suggest:
'Once the apphook is registered, you can remove the inclusion of zinnia.urls in urls.py and then restart the server to see it in full effect.',
but instead I get a NoReverseMatch at /name_of_my_blog_app/ exception, which only disappears if I include the zinnia.urls as above without namespace.
As a few weeks have passed since your original post, you may have resolved this by now. If not, I hope this points you into the right direction. In case you ran into the same issues (EntryMenu not loaded) at some point and were able to resolve, please let me know.

By using dev version for django-blog-zinnia, I see 'EntryMenu not loaded' no more. All menus related errors are gone now. As my understanding goes, this is due to inherent namespace issue in zinnia. Fantomas42 looks covering it in development version.
It has been tracked on https://github.com/django-blog-zinnia/cmsplugin-zinnia/issues/29

Related

Why does django continues naming my app as the previous name?

thanks for reading.
When I run "py manage.py makemigrations" I get the following message:
"ModuleNotFoundError: No module named 'transformaTe'"
This is the apps.py code:
from django.apps import AppConfig
class TransformateConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'transformate'
The name is updated there and in my INSTALLED_APPS:
INSTALLED_APPS = [
'transformate',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
Where else should I look to change the name of the app?
This is the simplified structure of the app:
\my-app
\transformate
admin.py
apps.py
models.py
urls.py
views.py
\my-app
asgi.py
settigs.py
urls.py
wsgi.py
All this happened when I rename the app because I had a problem creating a table called transformaTe_myuser so I though all could be caused by the capitalized letter use.
Is there a better way of renaming an existing app in Django? I followed this steps, except for the migration part (Because I deleted the db and the migrations folder):
https://odwyer.software/blog/how-to-rename-an-existing-django-application
Thanks for your help.
Well, it turns out that when you run makemigrations you have to check the project urls.py file, that was the only thing that was crashing my migrations.
ORIGINAL my-app/urls. py FILE:
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('', include('transformaTe.urls')),
path('admin/', admin.site.urls),
]
NEEDED FILE:
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('', include('transformate.urls')), # Here was the bug
path('admin/', admin.site.urls),
]

How to setup path (urls) for multiple Django applications in a single Django project

I have a single Django project which has two different Django applications, MyApp1 and MyApp2 (changed their names).
The structure is like this:
MyProject
MyApp1
static
templates
urls.py
views.py
...
MyProject
settings.py
urls.py
...
I wrote the MyApp2 as a separate application in a different Django project and integrated it with the MyProject project (pip install MyApp2). Here is the installed apps in the settings.py file:
# Application definition
INSTALLED_APPS = [
'MyApp1',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'MyApp2',
]
These are the following paths (urls.py) of the MyProject.
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('myapp1/', include('myapp1.urls')),
path('', include('myapp1.urls')),
path('myapp2/',include('myapp2.urls')),
]
These are the following paths (urls.py) of the MyApp1:
from django.urls import path
from . import views
from django.urls import path
from . import views
urlpatterns = [
path('', views.home, name='home'),
path('about/', views.about, name='about'),
path('contact/', views.contact, name='contact'),
]
These are the following paths (urls.py) of the MyApp2:
from django.urls import path
from . import views
urlpatterns = [
path('', views.login, name='login'),
path('index', views.home, name='home'),
path('dashboard_output', views.dashboard_output, name='dashboard_output'),
path('login', views.login, name='login'),
]
On the browser, if I type http://127.0.0.1:8000/ or http://127.0.0.1:8000/myapp1 I get the view of the MyApp1.
On the browser, if I type http://127.0.0.1:8000/myapp2 I get the view of the MyApp2 (the login page).
So far so good, but if I type http://127.0.0.1:8000/myapp2/index the system directs me to the view of the myapp1 instead of the view of the myapp2. What am I doing wrong? Any ideas?
I finally found what is causing the problem. It has to do with templates. Check out this:
https://www.webforefront.com/django/customizedjangotemplates.html
It is really important how Django works. If you have multiple applications and if APP_DIRS is set to true ('APP_DIRS': True) in the settings.py file, it checks out all templates directories of each application in the order of the applications in the INSTALLED_APPS. Long story short, since I had index.html files in templates directories of both MyApp1 and MyApp2 applications, it was overriding the index.html file of the MyApp2's template directory with the index.html file of the MyApp1's template directory.
As a solution, I just added a subdirectory called myapp2 under the template directory in the MyApp2 application and included the subfolder name while rendering it.
MyProject
MyApp1
static
templates
index.html
...
urls.py
views.py
...
MyApp2
static
templates
myapp2
index.html
...
urls.py
views.py
...
MyProject
settings.py
urls.py
...
As I said, I added the subdirectory name (myapp2/) to the render function's second parameter. Here it is:
...
return render(request, "myapp2/index.html", result)
I could add a subdirectory to the templates folder in the MyApp1 too but just didn't prefer it for now, because it really got a big application and didn't want to mess up with it.
Anyway, the solution worked!

Django urls.py mechanism

Recently I started my web project using Django with reference to some youtube tutorials. I have created a project named admin and created an app named user. From many tutorials they have created separate urls.py for both project and app. But in my case only the project's urls.py is working.
For example, I have defined the index view (my home page) in project's urls.py and login view in app's urls.py. When I try to access the login as it shows:
The current path, login, didn't match any of these
Can anyone help me to find out the solution for this?
Django only checks the URLs of the project's ROOT_URLCONF e.g. urls.py. If you want to include the URLs of a certain app, you can do the following:
In your projects urls.py:
from django.urls import include, path
urlpatterns = [
path('user/', include('user.urls')),
# others...
]
Then, if you go to url yoursite.com/user/, it will find the URLs specified in the app's urls.py. For more information see the docs.
Also make sure that your app user is in the INSTALLED_APPS of your settings.py, like this:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
...
'user',
...
]
So that django knows about your app.

Django Tutorial - Part 1 - URL didn't match

This has been asked before, but the problems were usually with placement of the mysite/urls.py or missing text somewhere. I've gone over those in detail, but doesn't apply here. I'm following the django tutorial EXACTLY, which means it hasn't referenced including the polls app in the settings.py file. I can pull up the right view if I manually type in the "polls" at the end of the url, as in "http://127.0.0.1:8000/polls" but I shouldn't have to do this for it to work. I'm also assuming the tutorial isn't wrong in some way. Link to the tutorial is: https://docs.djangoproject.com/en/1.9/intro/tutorial01/
The error I get:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
^polls/
^admin/
The current URL, , didn't match any of these.
My views.py file:
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world. You're at the polls index.")
My polls/urls.py file:
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
]
My mysite/mysite/urls.py file:
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^polls/', include('polls.urls')),
url(r'^admin/', admin.site.urls),
]
This is the tree for the mysite/mysite directory just to show that I am in the right folder (there is no separate urls.py file in the main mysite directory):
.
├── __init__.py
├── __pycache__
│   ├── __init__.cpython-35.pyc
│   ├── settings.cpython-35.pyc
│   ├── urls.cpython-35.pyc
│   └── wsgi.cpython-35.pyc
├── settings.py
├── urls.py
└── wsgi.py
Again, best I can tell this is to the letter following the django tutorial guidance. I'd like to fix it, but more importantly understand why it isn't working.
Have you checked the INSTALLED_APPS variable in the settings file to include the 'polls' app?

Django "ImportError at /"

I am getting an import error on a very basic test site I am trying. Below is the error message:
ImportError at /
No module named tickets
Request Method: GET
Request URL: http://dcdev1.dcevolve.com/
Django Version: 1.5.1
Exception Type: ImportError
Exception Value:
No module named tickets
Exception Location: /usr/lib/python2.6/site-packages/django/utils/importlib.py in import_module, line 35
Python Executable: /usr/bin/python
Python Version: 2.6.6
Python Path:
['/home/django/dcdev1',
'/usr/lib64/python26.zip',
'/usr/lib64/python2.6',
'/usr/lib64/python2.6/plat-linux2',
'/usr/lib64/python2.6/lib-tk',
'/usr/lib64/python2.6/lib-old',
'/usr/lib64/python2.6/lib-dynload',
'/usr/lib64/python2.6/site-packages',
'/usr/lib/python2.6/site-packages']
Server time: Mon, 5 Aug 2013 02:58:39 -0500
My directory structure is this:
-/home/django/dcdev1
-/home/django/manage.py
-/home/django/tickets
Under dcdev1 there are __init__.py __init__.pyc settings.py settings.pyc urls.py urls.pyc wsgi.py wsgi.pyc
Under tickets there are
__init__.py __init__.pyc models.py models.pyc templates tests.py views.py views.pyc
Relevant settings.py sections:
TEMPLATE_DIRS = (
"tickets/templates",
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'tickets',
# Uncomment the next line to enable the admin:
# 'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
urls.py:
from django.conf.urls import patterns, include, url
from tickets.models import ticket_info
# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()
urlpatterns = patterns('',
# Examples:
url(r'^$', 'dcdev1.tickets.views.home', name='home'),
# url(r'^dcdev1/', include('dcdev1.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
# url(r'^admin/', include(admin.site.urls)),
models.py:
from django.db import models
class ticket_info(models.Model):
from_address = models.CharField(max_length = 30)
to_address = models.CharField(max_length = 30)
subject_id = models.CharField(max_length = 100)
body_text = models.TextField()
recv_timestamp = models.DateTimeField()
views.py
from django.shortcuts import render_to_response
from tickets.models import ticket_info
def home(request):
return render_to_response('index.html')
I am working off of the guide at http://net.tutsplus.com/tutorials/python-tutorials/python-from-scratch-creating-a-dynamic-website/
There seems to be some differences in his directory structure vs mine. I'm guessing something had changed in later django versions. I have never used django, just trying it out to see if it will work for a project. Any help would be much appreciated.
In urls.py
try these
url(r'^$', 'tickets.views.home', name='home'),
instead of these
url(r'^$', 'dcdev1.tickets.views.home', name='home'),
Also you can run python manage.py validate and maybe you will see something useful.

Categories

Resources