How to Add a Basic StreamField to your Wagtail CMS Page

  Рет қаралды 26,363

Coding For Everybody

Coding For Everybody

Күн бұрын

In this lesson we are going to learn how to add a basic StreamField to a a generic Wagtail CMS Page. We'll create a new app from scratch, and this StreamField will have a title and text (using StructBlock), a custom template, and it will lay the foundation for the next lesson which covers inheriting RichTextBlock and modifying the features it can have.
Tutorial Link: learnwagtail.com/tutorials/ho...
Git Commit (includes Part 2): github.com/CodingForEverybody...
Learn Wagtail from scratch with the official Wagtail for Beginners Course
learnwagtail.com/wagtail-for-...
Used in this video: Wagtail 2.4, Python 3.7, Django 2.1.5 #Wagtail #Django #Python

Пікірлер: 42
@CodingForEverybody
@CodingForEverybody 4 жыл бұрын
For more videos like this, check out learnwagtail.com and the entire KZbin playlist at wagtail.io/course
@RukyasuX
@RukyasuX 5 жыл бұрын
I'm not much into commenting but thank you very much for this series, Kalob. This is undoubtedly the best learning source for Wagtail so far
@casumoto2115
@casumoto2115 3 жыл бұрын
A brilliant tutor, I just couldn't wait until end of the lesson to make this comment.
@addohm
@addohm 4 жыл бұрын
In wagtail 2.6.1 it is required to specify a name for a streamfield block. ('title_and_text', blocks.TitleAndTextBlock(classname='text_and_title') or you will get the exception: env/lib/python3.7/site-packages/wagtail/core/blocks/stream_block.py", line 44, in __init__ block.set_name(name) TypeError: set_name() missing 1 required positional argument: 'name'
@MortenRostved
@MortenRostved 4 жыл бұрын
Thanks :)
@NoahSky
@NoahSky 2 жыл бұрын
thx you literally saved my day xD
@boasorte6808
@boasorte6808 2 жыл бұрын
Brother, you are amazing. I have learned a lot and incredibly fast, you have an innate talent for teaching. And I am also following the videos with a low level of English, only with the automatic translation of the KZbin subtitles. Greetings from Chile!
@DarrenbyDesign
@DarrenbyDesign Жыл бұрын
This is awesome! Thanks for your time and energy
@umut2243
@umut2243 3 жыл бұрын
After 11:25 when i run 'runserver', error occurs: OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: '' When I run 'migrate' or 'makemigrations', error occurs: No module named 'streamswagtail' Python: 3.6 Wagtail: 2.9.3 Django: 2.2.15
@votelearn1244
@votelearn1244 4 жыл бұрын
Hi Thanks for the great course, I have a blog which users can add articles and I want user to have the ability to make collection or group and add their articles to it (something like youtube where you can add videos to playlist) .. what is the best way to do it with wagtail ?
@CodingForEverybody
@CodingForEverybody 4 жыл бұрын
Good question! There are LOTS of ways to do this. The simplest method would be to create another page (ie. ArticleCollectionPage) and use an Orderable to select blog pages. You could also use a StreamField as well but imo that's not using StreamFields for its intended use (that's not official, just my opinion). But a StreamField would work!
@votelearn1244
@votelearn1244 4 жыл бұрын
​@@CodingForEverybody thanks for your replay, I love you man :D okay, your suggestion is great if I want to make users add articles to his collection from (ArticleCollectionPage) .. but what if I want to give him the ability also to choose the collection in the article page (ArticlePage), something like when you create article and choose category or tags. how to make this ? and thanks again you are a life saver.
@CodingForEverybody
@CodingForEverybody 4 жыл бұрын
@@votelearn1244 Same way, its just one more layer of recursive code. You could create a Clusterable Model with an Orderable, register the Clusterable Model with the model admin and register as a snippet, and then use a SnippetChooserPanel. You'll see an example of this in the Menus app github.com/CodingForEverybody/learn-wagtail/blob/master/menus/models.py#L17-L80
@patriotlightning7791
@patriotlightning7791 5 жыл бұрын
It seems django-debug-toolbar is causing some weird bug in the latest release of Wagtail "index error out of range" something, when I try to edit a page in the admin area. Disabling it fixes the problem. :P
@CodingForEverybody
@CodingForEverybody 5 жыл бұрын
So I've heard. Very strange. I havent upgraded to Wagtail 2.5 with Debug Toolbar yet. When I do, and if I can find a solution, I'll make a video about it!
@SeanCotton
@SeanCotton 5 жыл бұрын
I'm getting the same error "list index out of range" when I try to edit the about page in the admin panel. @@CodingForEverybody Is there a way to downgrade Wagtail from 2.5 or remove the DDT?
@CodingForEverybody
@CodingForEverybody 5 жыл бұрын
Of course there is. I'd suggest removing DDT instead of downgrading Wagtail though. To remove DDT you can remove the DDT lines from your middleware and installed apps in dev.py. And to remove it entirely you can use `pip uninstall django-debug-toolbar` And if you really wanted to downgrade Wagtail, you could use `pip install wagtail==2.4` If you're on Wagtail 2.5 right now, make sure you upgrade to 2.5.1 as there was a bug that was fixed. `pip install wagtail --upgrade` or `pip install wagtail==2.5.1`
@marquesjohnson870
@marquesjohnson870 5 жыл бұрын
Not sure what I'm doing wrong, but my StreamField shows : title Name of title text Text I put in. Is that just because it's development mode, or am I doing something incorrect? I tore the whole project down and started over, and still got this output.
@CodingForEverybody
@CodingForEverybody 5 жыл бұрын
I'd need to see more of your code. You can put it up in a GitHub Gist. But generally you need to: 1) Add the StreamField field (ie. blocks.CharField) to your StreamField, and 2) Add the new field to your template (ie. {{ self.new_field_name }}
@marquesjohnson870
@marquesjohnson870 5 жыл бұрын
@@CodingForEverybody the reason none of this is working for me, is at this step templates are not even being looked for. After putting the info for streams/blocks.py and trying to refresh "About" the page refreshes without the template error. So it seems its not even trying to access templates any more. Everything in flex_page.html and home_page.html, seems to go through the template, though.
@CodingForEverybody
@CodingForEverybody 5 жыл бұрын
@@marquesjohnson870 If there's no template error, it means it's found the template. Your loop looked like it was working. But this thread is getting a bit long to provide support on KZbin. Have you joined the Slack community yet? wagtail-slack.now.sh/ We can help you out a lot more in there!
@marquesjohnson870
@marquesjohnson870 5 жыл бұрын
@@CodingForEverybody I have joined there. But it couldn't have found the template because I hadn't made one yet.
@CodingForEverybody
@CodingForEverybody 5 жыл бұрын
@@marquesjohnson870 If you have DEBUG = True in your settings, and you're using a StreamField on a page and you're requesting a template that doesn't exist, you'll get a Template Does Not Exist error. First step is to get ANY streamfield template to render. It doesn't need dynamic content, it just needs SOMETHING to show up. I'm looking forward to seeing you in the Slack community!
@abdulia1194
@abdulia1194 4 жыл бұрын
Everything works but I keep getting this: --module streams --unresolved import 'streams' Server still runs but the error annoying. How can I remove it. Btw, great video tutorials. I can see big potential for Wagtail.
@CodingForEverybody
@CodingForEverybody 4 жыл бұрын
"streams" isnt a module in your code. You just ned to remove the line that starts with `from streams import ....`
@SpiffyguyAdventures
@SpiffyguyAdventures 3 жыл бұрын
Why are you creating a new app for each page? Wouldn't it be better to just add it to the original models.py and create a new html template? Just getting started with the series so there is probably a good reason. But so far there are now 3 apps created.
@CodingForEverybody
@CodingForEverybody 3 жыл бұрын
In these videos, practice. And to also split out larger chunks of logic, should we need to. Separating the apps now is easier than having to do it in the future and writing a data migration. Though I've seen pages all living under one models.py file and there was nothing wrong with that.
@SpiffyguyAdventures
@SpiffyguyAdventures 3 жыл бұрын
@@CodingForEverybody ok thanks for the reply. That makes sense. My previous Django project has a singular models and used views, so wagtail is a bit different. Thanks for these tutorials they have really helped.
@harsha44467
@harsha44467 5 жыл бұрын
I keep getting this error on creating a StreamField, the block has 2 simple CharBlocks, please help? ERROR: AttributeError: 'list' object has no attribute 'get_prep_value'
@CodingForEverybody
@CodingForEverybody 5 жыл бұрын
Can you put your StreamField into a gist (gist.github.com/) and share the URL with me? And maybe also include your page class that's trying to use this streamfield. My first thought is that you might be using a ListBlock. Or the `content = StreamField(...)` property is misconfigured.
@ruchitmicro8409
@ruchitmicro8409 5 жыл бұрын
I've got the same issue
@harsha44467
@harsha44467 5 жыл бұрын
@@ruchitmicro8409 deleting all migrations and dropping the table helped for me. Just makemigrations again
@ruchitmicro8409
@ruchitmicro8409 5 жыл бұрын
I got it solved this is what I did, find . -path "*/migrations/*.py" -not -name "__init__.py" -delete find . -path "*/migrations/*.pyc" -delete paste the above two code in a terminal targeting your project directory (It will remove your migrations). Then, remove db.sqlite3 from your project directory. Then makemigrations and migrate My mistake was I didn't watch the entire video where Kalob skipped giving default value when asked during the migration and I gave the default value. Hence my code got fucked up
@ArjitRaj
@ArjitRaj 4 жыл бұрын
@@ruchitmicro8409 Thank you.
@abdojoba8932
@abdojoba8932 5 жыл бұрын
server gives me an error "no module named streamswagtail"
@CodingForEverybody
@CodingForEverybody 5 жыл бұрын
Make sure you're adding "streamswagtail" to your base.py file (in the INSTALLED_APPS) and make sure your directory is called "streamswagtail". In this video and the the source code I'm using a module called "streams", the name is slightly different but very important.
@abdojoba8932
@abdojoba8932 5 жыл бұрын
I forgot the comma after the app (streams) Thank you very much @@CodingForEverybody
@alexmangir
@alexmangir 4 жыл бұрын
I have same problem, but my base.py is correct. (Django==3.0.6, python==3.8, wagtail==2.9)
@danielabrahams4061
@danielabrahams4061 3 жыл бұрын
@@alexmangir Me too - did you solve this issue? I can't find much online about it
Creating a Call to Action StreamField in Wagtail CMS using a StructBlock
18:53
Coding For Everybody
Рет қаралды 10 М.
How to Use ListBlocks in Wagtail CMS to Create Repeating StreamField Content
19:52
I wish I could change THIS fast! 🤣
00:33
America's Got Talent
Рет қаралды 76 МЛН
Vivaan  Tanya once again pranked Papa 🤣😇🤣
00:10
seema lamba
Рет қаралды 22 МЛН
Wagtail CMS: How to Create a Custom Wagtail Menu System
38:22
Coding For Everybody
Рет қаралды 19 М.
How to Add a RichText StreamField to your Wagtail CMS Page
12:09
Coding For Everybody
Рет қаралды 13 М.
How to use Orderables in Wagtail CMS
22:42
Coding For Everybody
Рет қаралды 14 М.
Comparing Wagtail, Django CMS and Mezzanine
30:59
PyCon AU
Рет қаралды 29 М.
Headless Wagtail CMS: How to Enable the v2 API to Create a Headless CMS
18:06
Coding For Everybody
Рет қаралды 10 М.
Adding User Registration/Login To Your Wagtail Website
23:03
Coding For Everybody
Рет қаралды 15 М.
Protocol Buffers Crash Course
36:07
Hussein Nasser
Рет қаралды 235 М.
Wagtail CMS: Registering Snippets using Django Models
13:35
Coding For Everybody
Рет қаралды 10 М.
I wish I could change THIS fast! 🤣
00:33
America's Got Talent
Рет қаралды 76 МЛН