 As a note, Senna will be giving a lightning talk today, and it's her first talk ever, and it's on great ideas for being productive as a developer. So show up, give her some love. I'm going to give a, I love walking around, but I have to sit back here, and I'll do my typical, can you hear me okay? Can you see me okay? I'm going to talk today about PyCharm and Django. We're going to have a lot of fun. It's my job to entertain you, it's your job to entertain me as well. Come up close, let's tell some stories. I've got a one-hour presentation to give in 30 minutes. Let's jump right in. The topic of this talk is how to be a bad-ass at Django using a bad-ass tool like PyCharm. Some of these are beginner tips, some of them are more advanced, and if you know something better than me, stick your hand up, shout it out, see if you can embarrass me on stage trying to recreate it. So I'm going to talk about some things. I'm going to start with things that PyCharm Professional can do for you that are more convenient. For example, I'm going to go over to PyCharm, and how am I doing as far as font size and stuff. You want it bigger? Yeah. All right. Good. As a senior citizen, I endorse that. All right. And I'll go up to 125. How about that? Is that all right? Okay. I have opened a project already. What if you didn't have a project? Tip number one, PyCharm will help you make a new project in Django, and it will go and get the Django software for you, create a new project, create a virtual environment for you, open it up, and you'll be ready to go. One of the things that we really have tried and tried again and tried five more times is to figure out Python virtual environments and how we can take care of them for you without making things worse. So we have different ways to make Python environments a lot easier from within the IDE. So for example, I have the status bar down here. I should have mentioned I'm using what's called new UI. We gave in the last couple of releases we have an overhaul for a leaner developer experience. I'm using the new UI in the wrong theme known as the dark theme because I didn't want all of you yelling at me incorrectly with your dark theme ideas. So down here I've got the status bar and I can go to make a new interpreter, which is a virtual environment. I have different ways. I can add remote ones, local ones, using all of the different ways that Python likes to help you, and I can say an existing one or a new one, and when I click it, it gets attached to my project automatically. Then when I'm in that, if I went to my requirements.txt and I hadn't installed my packages, PyCharm would lovingly pop up a note saying would you like us to install your packages for you? Why? Yes. Thank you, PyCharm. That would be really nice of you. So we have some ways to get you started that are a little bit easier. That extends to full stack as well. PyCharm is a Python IDE. Well, Python in full stack means front end, back end, database. So PyCharm professionals ships with WebStorm, our IDE for JavaScript, and DataGrip, our IDE for SQL. So for example, I have in this project a package.json file. You can see I've got React code in this project. And I can walk up to my package.json, right click on it and say run NPM install. I'll go ahead and do that. I could go wrong. It's JavaScript after all. And it will install my packages for me. I could go even further and I could, for example, what's one of these? We'll go with this. I'll actually go here and say, hey, autocomplete of package names, great. And I can say autocomplete of version names, oh, that's really helpful. Oh, and now that I've done that, I might need to do an NPM install. And I could alt enter on that and install my packages. So different ways to get your environment going, set up quickly, extends to Django as well. If you want to, for example, run make migrations, we have a manage.py tool. I've got installed down here. I've got the little plug-in that tells you what I'm typing. So I will go to, woop, I'll skip that part because of the network. I can run migrations and do other activities there. I can then run a run configuration that's tailored to Django. We have different ways to make run configurations. So for example, what do we support? We support these things. App Engine, huh, didn't see that one coming. We've got fast API support, flash support. We still have Pyramid support, Pyramid forever, Pyramid support, et cetera. I've got a Django server run configuration set up, which means I can just clickity click on this little button. It fires up the Django server. I get prompted because it detected that I had changed my package.json. I say yes, go get those packages. And I've got a Django server running. I can click on this URL, and there's Pyram. I will leave that in Firefox, the one true browser, play to the crowd, right? And let's see. I will go back over and browse this application and look at the polls. I'm showing you the official Django tutorial, kind of the endpoint, with some things added past that for this tutorial. So you see that I've got three questions in this tutorial. And so for the most part, my environment is set up. I'm ready to do some badass Django development. I'm going to talk about ways of coding that are my way of coding. One of you I was talking about, talking with before who said, is this going to be too basic for me? And I said there are going to be some things here for you. So if you're here, this is the part that's for you. I don't believe in files. We are an IDE. We index all of the things. We index your get commit messages. And we turn those into symbols, and you can navigate by symbols instead of navigating by filenames. So if I wanted to go open the polls applications views, so you see there's a directory, and I could go down, I could go find, I could double click on it. Actually, I'll make it a little bit better. I can double click on it, and it opens it. But life's too short for that. I turn off as much as I can in my IDE. I turn off tabs. I usually turn off this status bar thing down here. So status bar. And I've got a pretty lean experience. And when I want to navigate to the index view in the polls Django app, I don't go diving around in files and directories, because I've already forgotten their name by the time I created it. Instead I navigate by symbol. You can see the command sequence I did at the bottom. And I type index view, and you see that there were two of them. So that's inconvenient, because now I have to move my hand over three centimeters and hit down. And that's just too much trouble. So instead I would go to the polls index view by saying po.iv. And there it is. And when I hit enter, I don't jump to the file, I jump to the symbol, the place that I was looking for, and my cursor is right on top of it. So that's one of the first power tips is to think of symbols, don't think of file names. All right. Now, I might also want to do things like that for jumping to templates. That's a little bit of a problem, because the Django template isn't necessarily a Python symbol. So if I want to jump by maybe a path, I might use my search everywhere. And I might type TEM slash BAS to jump to my base dot HTML base template. And I could hit enter there. So I'll go ahead and do that. On the previous one, though, when I was on the views, what if I want to go to the template for this view? We've been doing this Django game for a long time. There was a question earlier, when did PyCharm start 2012 at a Euro Python? And so we've got little things like navigate from the view to the template and navigate from the template to the view. So we keep that association there. But back to the base HTML template. And in here, I have this PyCharm logo, and I'd like to just get rid of it. The Django server is running, and it's running in that debug mode, so it will see file changes and template changes and all that other stuff. So if I come here and I want to delete this line, when I do, and it's safe, and reload the browser, you'll see the change. But this gives me an opportunity to show you we treat Django template stuff like symbols. For example, static, I mouse over it, and it treats it like a Python symbol and tells you as much as it can tell in this little inlay hint about it. It autocompletes on it. Big whoop, lots of template languages have supports and editors. But how about this, autocomplete in there of the file system? So that's not that bad. What if I got it wrong like that? Well, I'll do this. Like that. It's warning me that that doesn't exist. And that will actually show up in the problems view for the entire site. So I can put this back the way it was, and then delete that line. Like I said I would, go over, reload the browser, and the logo is gone. So that's pretty cool, and it's beginning this theme I'm going to talk about quickly for 12 more minutes about looking at symbols instead of strings. This is a magic string in Django. We taught the PyCharm IDE how to index it into symbols. Let's take a look at another thing. I'm going to go back to that view. And here I'm currently showing up to 10. If I show just one, hit reload, I'll only see one. Django restarted the process. I'll put it back the way it was. All right. And let me speed up to skip over some of the more basic things. We talked about indexing strings. I want to go to my installed apps. Where is that file? This is Django. I know it's got a special name in a special place. Wouldn't it be better if I could just go to installed apps? So that's a lot better. Well, here's a whole bunch of strings. But if we know that this is in this special file with this special name, maybe we can treat those as paths as well, and we can do things like navigate to them, and then navigate back. Navigate to them, then find all the usages for these things. And that was the only usage. All right. I'll talk a little bit more about template support when we get into debugging. I'm going to shove an agenda on you, which is testing. Raise your hand if you do testing. Raise your hand if you do testing. For the record, everyone raised their hand. Raise your hand if you love testing. You love it when other people write the test. There you go. All right, cool. I do testing not because I want to eat my vegetables and I believe in quality. I see some faces out there. They know me. I don't believe in quality. I'm a lazy. So what I believe in is working smart. We were talking about Cata, right? And that's what your talk is on about Cata. I do test-first development, not test-driven development, so that I can stay in the flow. What does staying in the flow look like for me? I will split the, no, I will not do that. I will split my code, and I will have my index view on this side, and I'll have my tests on this side. My tests are in PyTest instead of DjangoTestRunner. And I'll stop the Django server, and I'll walk up to this one test, which is testing this index view, and I will run the test. Great, my tests pass into presentation. Now, I want my tests to fail, and I want to be in this kind of working really smart mode. So I'm going to click here to rerun the tests automatically. I'll let it know that I did that. And now, if I say that, then after two seconds, my test, this configurable time limit, my tests fail. And you saw that I saved, but I didn't really have to save. I can go into this mode where I'm just coding, and it's running, I can even close this thing and know that my tests ran and failed. So I'll go back to my test running. I see that my test failed. I'll put it back the way it was. Here's the beauty part of this. I'm a man of a certain age. I can only remember three things. What I was doing 10 minutes ago is not one of those three things. And so I need the debugger to poke around, not to fix problems, to just go look around. I don't really know the Django API here. I don't really know what's going on. So I can set a debugger breakpoint there. And I could, just for fun, I'll go into the template and set a breakpoint on this image tag. And I'll do the template in a second. I'll go back to this. And now, when I run my tests under the debugger, I stop on that breakpoint. And I'm really mega in the flow. Code on the left, test on the right. And that signals my brain that I'm in a happy place. And I can poke around and fix my problems. What if I wanted to do that for the magical world of Django templates? I could put a breakpoint in the template. And this time, I'll run it in a more realistic setting of running it in the Django server under the debugger. The debugger's pretty fast, so it's already started up. And now, when I get a list of, when I go refresh the browser, it's stopping on the breakpoint in the template as if all of these things, like latest question list and the current question, were Python things. And I can look around. I can type commands here like question dot and get autocomplete as if I was in the middle of the editor. Test first plus debugging is a very happy place. I'm going to get into a couple of extended features. For example, Yakov, do you mind standing up? Give the sales pitch on what I'm about to talk about. Turn around and face them. Yep. Ha ha ha. I talked them into this. I was getting serious. Yeah, you'll for sure sooner or later be in the need of doing requests. And we can all do a get request from the browser. Nothing hard to add. But me, or I believe others, find really hard to do a post request from the browser. You'll need a postman for that, or you can hack some corollary requests, or do the JavaScript in the Chrome development tab. But as Paul is going to show, the PyCharm has a really great integration for it. It also saves the responses to the files. And itself is a file, so you can commit it to your favorite source control. So it's a round of applause for Yakov, who believed me when I said that I wouldn't really put them on the spot. These are files you can put into source control and issue HTTP requests and get all of the support of the IDE. I want to look at the HTML listing. I walk up to it, run it. And I see the HTML. I want to get a JSON listing, run up to it. I can run it under the debugger, all of these things. I can get autocomplete. HTTP file support is a wonderful way to stay in the flow. Do your work in the IDE where you already know most of the things. Then for the front end, PyCharm and Django, Django's really embraced Django REST framework with things like React in the front. We've got a world-class JavaScript ID bundled in PyCharm Professional. It's called WebStorm. So I can walk up to or I can do app component. I can walk up to an app component. I can navigate to things. I can run VTest tests in that same test runner that I was just talking about under a debugger, just like you would do in the back-end tools. Very good support for front-end work and support for the thing that many people just find irresistible. DataGrip, our database for SQL. This is a Django app with a SQLite file. And if I go to the database tool, I configured it already. But you can double-click on a SQLite file and open this up automatically. I'm connected to the database and I can, let's see, question number one. I can go to the poll questions. Look at the table. I can issue queries. I can walk up and edit this. Tons of features, it's a very mature product and extends over into Python and PyCharm by letting you do, let me see. Letting you, in Python, in a Python file, we have language injection and you can put SQL in Python and get autocomplete and refactoring and navigation of your SQL. Wrapping up some things that we just shipped if you're interested in talking to me afterwards, black integration, finally, yay. But wait, there's more. It's badass black integration. I'll show it. You can tell PyCharm to use black when you use the normal PyCharm things, like saving a file or just doing reformat, it will take that over. We have ORN support, so with something called endpoints, where in your JavaScript, it can know your open API schemas and autocomplete and refactor in JavaScript or in other places. We've got, raise your hand if you do type hints. Raise your hand if you will never, ever do type hints. Okay, some of you are lying. We have the David Beasley feature. David Beasley did this awesome tweet with an enormous type hint and saying, is this what Python is turned into? We've got support for folding your type hints into a triple dot and hiding them until you actually want them. I think that's just great as a big believer in typing. I'll be here for a few more minutes. I'd love to answer any questions. I will wrap up. We've got time for one question or one tip from the audience. Am I out of time? Or you're asking a question? Question. Yeah, great. You showed debugging of the Django templates. Is that possible to do with other Django templates? Yes. Yes. Template debugging is for both of the template languages. I'm not sure if Chameleon supports debugging. All right. Thank you very much. Come over to the booth and you tell me the tip I should have shown. Thank you.