I am using:
Python 2.7
Django 1.6.11
Mezzanine 3.1.10
Anyone who logins in my blog website can set the "name" field of the comments form for a blog post. I had the idea to hide this field but I can't find the template for the comment form.
Does anyone know where the comment form template is or another way to prevent users from setting the "name" field for comments?
You can try to change the templates by first copying the relevant template into your static/templates directory. Use the command
./manage.py findstatic templates\something.html
Ensure that your static files directory is set, then check that
./manage.py findstatic templates\something.html
finds both files, one from mezzanine and one from your static directory.
Example:
./manage.py findstatic css\bootstrap.css
Found 'css\bootstrap.css' here:
C:\Python34\lib\site-packages\mezzanine\core\static\css\bootstrap.css
c:\users\me\documents\mezz-project\mez\static\css\bootstrap.css
Related
My current way of adding new pages to my wagtail site is the following:
Edit the installed apps to include my new page
INSTALLED_APPS = [
'home',
'anotherpage',
'newpage', # this is new
'wagtail.wagtailforms',
...
]
Copy the format of anotherpage to be my newpage
cp -rf anotherpage newpage
Edit my newpage/models.py references to anotherpage to be newpage.
E.g.
class Anotherpage(Page):
becomes
class Newpage(Page):
And the newpage/migrations/0001_initial.py references
Rename: mv feedback/templates/info feedback/templates/feedback
and mv feedback/templates/feedback/info_page.html feedback/templates/feedback/feedback_page.html
etc
Then run python manage.py makemigrations
Then python manage.py migrate
Question
This workflow feels quite inefficient, is there a better way to be doing any of the above?
I'm new to python and wagtail. Any insight on what I could be doing better would be greatly appreciated
You don't have to create a new INSTALLED_APPS entry and app folder for every new page model you create - a single models.py file can contain as many page models as you like. Generally I'd recommend one app for each major area of your site - for example, you could have a blog app containing BlogPage, BlogIndex and BlogArchive page types. You can even define the page models for your entire site in a single app if you want - although that can get hard to maintain when the file grows very large.
This way, creating a new page model just involves adding the class Newpage(Page): definition to the existing models.py, running ./manage.py makemigrations, and adding a new template into the existing template directory.
Additionally, when you do decide to create a new app, you can make use of the ./manage.py startapp some_app_name command to save having to create files and folders manually.
I'm trying to extend an already existing Django App. The app is functioning fine as is, but I would like to add blog functionality.
I've installed Wagtail, using the guidelines here (http://docs.wagtail.io/en/latest/getting_started/integrating_into_django.html) To check wagtail is installed, I have navigated to here:
http://myurl/cms
And the wagtail admin panel is displayed. When I navigate to http://myurl/admin I get the default admin control panel for my Django app, so far so good.
Now I am trying to build the blog.
I found this tutorial:
http://wiseodd.github.io/techblog/2015/06/22/developing-wagtail/
which suggests the following as a first step: -
First, we’ll create our generic page class as home page class is
already created by default when we started Wagtail project.
It then displays this code:
# core/models.py
from wagtail.wagtailcore.models import Page
from wagtail.wagtailcore.fields import RichTextField
from wagtail.wagtailadmin.edit_handlers import FieldPanel
from wagtail.wagtailsearch import index
# We’re deriving our GenericPage from Page class, so that our GenericPage also has Page’s field, e.g. title
class GenericPage(Page):
# Let’s create our custom field, named body which is a rich text
body = RichTextField()
# Index the body field, so that it will be searchable
search_fields = Page.search_fields + (index.SearchField(‘body'),) # To show our body field in admin panel, we have to wrap it with FieldPanel and add it to Page’s field panel content_panels = Page.content_panels + [FieldPanel('body', classname=‘full’)]
I could not find which file I was meant to add this into. I searched the system using grep, and found a number of files that had the text string:
from wagtail.wagtailcore.models import Page
I decided the most likely candidate was in the directory:
env/lib/python2.7/site-packages/wagtail/project_template
Within my original app directory. I added the code above to the models.py file residing in the above directory. I then ran
python manage.py makemigrations
But it said no migrations were found. The next step in the tutorial posted above suggests you should now see three different page types available to create in the control panel, but I can not find the option to create any pages.
Can you tell me if I edited the correct file above, or if I should have edited a different file, and also
Why I am not seeing any option to add a new page in the wagtail control panel?
I have consulted with the documentation here (http://docs.wagtail.io/en/latest/getting_started/tutorial.html) and tried following the 'extend the homepage model' section, but couldn't figure out where the home/models.py file is as there is no folder called home in my Django app.
Thanks for any advice
As the final section of the "integrating into Django" docs says:
You’re now ready to add a new app to your Django project (via ./manage.py startapp - remember to add it to INSTALLED_APPS) and set up page models
Running ./manage.py startapp blog will add a blog app to your project, including an empty models.py - this is where you add your page definitions. (The Wagtail docs don't go into detail on this, because it's just following the standard Django workflow, which is hopefully familiar to anyone with an existing Django project to integrate with...)
Tutorials that use wagtail start my_project as a starting point will omit this step, because the starter project comes with a pre-made models.py with a HomePage model. The site-packages/wagtail/project_template directory you found is actually the 'master' copy of the starter project, which gets cloned at the point that you run wagtail start my_project. Since this isn't hooked up to your current project, changing it had no effect.
I've been struggling with Django registration redux over the past two weeks. I'm using the templates that were provided in the documentation and I've made a couple of changes like adding crispy forms and changing the button and some other stuff but the problem is that none of these changes are being shown on http://127.0.0.1:8000/accounts/register or any other link.
I'm using Django registration redux 1.4, Django 1.8, python 2.7.10
Putting your customized templates in templates/registration (not register) should work.
At least if your TEMPLATES setting is correctly configured: https://docs.djangoproject.com/en/1.8/ref/templates/upgrading/
And you probably already checked this hint from the project's FAQ?
I want to use custom templates, but django keeps using the admin
templates instead of mine!
To fix this, make sure that in the INSTALLED_APPS of your settings.py
the entry for the registration app is placed above
django.contrib.admin.
I want to pygmentize my text field python code in django admin template in a situation.
I have a python code block which is stored as a text field in django model.Here i stand with the situation of highlighting that python code with syntax in django admin change_form.html whenever you try to access that, it would be in proper syntax highlighiting style.
I have gone through some resources.
All are explained to make django template tag or filter with custom pygment template tag also, i got some nice article too.
1.http://od-eon.com/blogs/stefan/integrating-pygments-django/
2.http://djangosnippets.org/snippets/416/
But I am facing problem of using the template tags or filters in django admin change_form.html ?
Or How can we do the syntax highlighting through django model admin if this is the method should need to be passed (http://dpaste.com/hold/1280580/)?
Assuming you don't need ordering on the python code column, then you could simply render it using pygments API in a ModelAdmin method using list_display. Then you wouldn't need to touch django admin templates at all.
I would like to know the best way to replace a standard textarea field with a rich text editor in Django Admin?
There's an add-on Django application to provide TinyMCE support for Django admin forms without having to muck around with admin templates or Django newform internals.
Take a look on this snippet - basic idea is to include custom JS in your admin definitions which will replace standard text areas with rich-text editor.
For jQuery/FCKEditor such JS could look like that:
$(document).ready(function() {
$("textarea").each(function(n, obj) {
fck = new FCKeditor(obj.id) ;
fck.BasePath = "/admin-media/fckeditor/" ;
fck.ReplaceTextarea() ;
});
});
I'd say: define your own ModelAdmin class and overwrite the widget used for particular field, like:
class ArticleAdminModelForm(forms.ModelForm):
description = forms.CharField(widget=widgets.AdminWYMEditor)
class Meta:
model = models.Article
(AdminWYMEditor is a forms.Textarea subclass that adds WYMEditor with configuration specific to Django admin app).
See this blog post by Jannis Leidel to see how this widget can be implemented.
At the date of the post and the answers TinyMCE was quite popular (as it probably remains today).
But after some time ckeditor has appeared and many consider that a better alternative, including many SO users:
Compare TinyMCE and CKeditor for a Wiki
http://www.turnkeylinux.org/blog/tinymce-vs-ckeditor
There is also a 2013 review of WISIWYG editors with Django in Russian:
http://habrahabr.ru/company/htdt/blog/202782/
Currently the most straight forward way to use tinymce in django admin is to use Grappelli.
http://code.google.com/p/django-grappelli/
Grappelli is also a requirement for django-filebrowser so if you want the whole shebang you will gotta need it anyways.
class KindEditor(forms.Textarea):
class Media:
css ={
'all':(settings.STATIC_ROOT + 'editor/themes/default/default.css',)
}
js = (settings.STATIC_ROOT + 'editor/kindeditor-min.js',settings.STATIC_ROOT + 'editor/lang/zh_CN.js',)
def __init__(self):
attrs = {}
attrs['rel'] = 'kind'
super(KindEditor, self).__init__(attrs)
class NewsAdminForm(forms.ModelForm):
pass
class Meta:
model = News
widgets = {
'body':KindEditor()
}
class NewsAdmin(admin.ModelAdmin):
form = NewsAdminForm
admin.site.register(News, NewsAdmin)
Ok, to update a little this post, I would say that the easiest way to implement TinyMCE is to use the django-tinymce app. You must also download the JS files from the TinyMCE page. I got some errors with the django intenationalization, but downloading the laguage packs from the TinyMCE must be enough.
Install this package
pip install django-ckeditor
then run these commands to migrate.
python manage.py makemigrations
python manage.py migrate
python manage.py collectstatic
finally restart your Django server.
Once you complete the above steps, you can see the rich text editor in your admin panel fields.