Locked lesson.
About this lesson
In this lesson, we'll learn how to push our code to Heroku and rename your URL.
Exercise files
Download this lesson’s related exercise files.
Push Code To Heroku - Rename URL.docx57.6 KB Push Code To Heroku - Rename URL - Solution.docx
58.2 KB
Quick reference
Push Code To Heroku - Rename URL
Once our app is configured, it's time to push it to Heroku.
When to use
Do this to push your code to Heroku for web hosting.
Instructions
Make sure to save your code to git:
git add .
git commit -am 'tweaked for heroku'
git push
Then push your code to Heroku:
git push heroku master
To rename your app:
heroku rename YOURNAME
Hints & tips
- git push heroku master
- heroku rename YOURNAME
- 00:04 Okay, so we've configured our app, and it's ready to be pushed up to heroku.
- 00:07 So now we want to actually push it up to heroku.
- 00:10 So head back over to our terminal.
- 00:12 And let's go ahead and clear the screen.
- 00:14 Now we've made a bunch of changes to our app.
- 00:16 So we need to save this to our Git repository both locally and
- 00:19 probably at GitHub.
- 00:20 Let's go git add.
- 00:21 git commit-am, and
- 00:24 I'll say 'configured for heroku'.
- 00:32 Okay, and then git push, to push all this code up to GitHub.
- 00:39 And now we can close the screen.
- 00:40 Now, in order to push our code from here to heroku we use the command
- 00:45 git push heroku master.
- 00:47 We're pushing the master branch, this branch right here,
- 00:51 you see this master up here.
- 00:52 This is our master git branch, pushing our master git branch to heroku, and
- 00:57 that's it.
- 00:58 So hit Enter.
- 00:59 Now, this can take a minute, it could take three minutes, it could take ten minutes,
- 01:03 it could take 30 seconds, you never rally know.
- 01:06 And this is always sort of a finger crossed type of thing because we just made
- 01:11 some configuration changes.
- 01:13 And maybe we forgot something or maybe we misspelt something.
- 01:16 One time I misspelt in the prok file, I misspelled gunicorn,
- 01:21 I typed it is gunicord, right?
- 01:24 So it threw an error, so, you're never quite sure this is always kind of hold
- 01:27 your breath and hope there's no errors.
- 01:29 And see, you can see it's installing things that psychopg that postgres
- 01:34 database, there's our dj-database-url.
- 01:36 Here's all of our stuff, really running setup.
- 01:42 Now let's see, I failed to push some references, we got an error.
- 01:46 So this is good, I always want to show an error while I'm teaching courses because
- 01:50 you're always going to get them.
- 01:52 So what you want to do when you get an error,
- 01:54 there's a couple of things you can do.
- 01:55 The first thing is just read through this stuff and
- 01:57 it looks like an overwhelming bunch of gobbledygook.
- 02:00 But you could see we're saying a python manage.py collectstatic --noinput.
- 02:04 You need to update the application code to resolve this error, or
- 02:09 you can disable collectstatic for this application by typing in this command.
- 02:15 So this is a weird one, I've seen this before.
- 02:18 Sometimes it does this, sometimes it doesn't.
- 02:20 Heroku is a little finicky that way.
- 02:22 So it's saying you can get around this by just punching in this command.
- 02:26 So let's go ahead and do that I copied it, I'm going to paste it,
- 02:30 heroku config:set, DISABLE_COLLECTSTATIC=1 and hit that, okay?
- 02:35 So now let's get push heroku master, one more time.
- 02:44 And it's going through and doing the things, and installing our dependencies.
- 02:47 And I mentioned there's a couple of things you can do.
- 02:50 You can read through this stuff.
- 02:52 You can also type in the command heroku logs to words and
- 02:56 it's just let's pull this up.
- 02:58 It's just the command heroku logs and what that will do is show your heroku logs.
- 03:03 And a lot of times if there's an error, it'll be seen in the heroku logs.
- 03:07 So that's one way you can sort of check for
- 03:10 errors if you get errors because sometimes you look through all of this stuff.
- 03:14 And you can't really tell what's wrong or there isn't an error at all.
- 03:16 Though if that's the case, you would type in heroku logs and
- 03:20 it'll show you the log file.
- 03:22 And you can see hopefully in there what you need to do.
- 03:25 And a lot of times if you do get an error in the log file or even up here,
- 03:28 you can just copy it and paste it into Google.
- 03:31 And Google will tell you immediately what you have to do to fix it.
- 03:34 So, okay, this time we've got no errors.
- 03:36 Very cool, I'm going to go ahead and clear the screen.
- 03:40 And before I do that, you can see here is our URL from a couple of videos ago when
- 03:44 we created our app, okay?
- 03:46 Clear the screen, and now is the moment of truth.
- 03:49 We can come over, this is our local app.
- 03:51 If we come over here, this is our heroku app.
- 03:54 So now we just want to click Reload and yes it worked.
- 03:58 And I'll just show you really quickly, what I mean by the heroku
- 04:02 logs we come back over here and just type in heroku logs.
- 04:09 You can see there's all this stuff and this looks overwhelming.
- 04:11 But usually, you want to look towards the end.
- 04:13 because if there is an error, it usually is shown at the very end.
- 04:17 So like from here down, I would read, if there was an error,
- 04:20 now we don't have an error, so there's no error here.
- 04:22 But if there was an error, read down here at the bottom,
- 04:25 it'll say something you probably won't understand what it says.
- 04:29 But just copy it, paste it into Google, search for it and
- 04:32 you'll usually find a Stack Overflow article.
- 04:34 Or some other article explaining what the error is, and
- 04:37 showing you exactly how to fix it.
- 04:39 So, okay, very cool.
- 04:40 We've got our, this app is now live, this is on the Internet,
- 04:43 anybody can come to this website.
- 04:45 Now, we're using the free tier of heroku which is not very powerful.
- 04:48 So if like ten people came to the site at the same time,
- 04:52 it would be very slow to load.
- 04:54 You know what I mean?
- 04:55 So if you want more powerful you can go to Heroku and
- 04:58 pay for higher bandwidth and more powerful web hosting if you want.
- 05:02 But just for this purpose of showing you how to do it, this is great works fine and
- 05:06 is very cool.
- 05:07 So we can click around it does all the things, all right?
- 05:12 Very cool, and this website is completely done John Elder tech resume.
- 05:16 So we've got this URL djangoresume2.herokuapp.com,
- 05:21 but chances are you want your own URL.
- 05:25 You want your own domain name like johnelder.com, right or whatever.
- 05:29 So how do you do that?
- 05:31 We will take look at that in the next video.
Lesson notes are only available for subscribers.