Yes, you can get a mortgage after bankruptcy, but not right away, and not without some work towards rebuilding your credit.
After you've completed filing you are supposed to have a fresh start, but the truth is that you are viewed as a financial risk. Of course, if you take some time to build up a history of using credit appropriately then things will be much easier for you.
There are two types of payments that make up your financial history, revolving (credit cards) and installments (loans). You'll want to work on building up both of these. I recommend starting with a secured credit card and working on a small loan six months to a year later.
I would make it a goal to build towards getting a mortgage after bankruptcy after about two years. Hopefully, your credit will be at a decent, if not a good level, by this time.
When you go to apply you'll need to briefly explain what caused you to have financial problems in the past. I recommend trying to keep this explanation down to about two sentences, make sure you adequately explain what happened (medical bills, divorce, etc) but don't spend too long focusing on this fact.
Instead, focus on what you have done since then rebuilding your credit, and other signs of your stability. For instance, if you've been with the same employer for a long period of time, or if you have lived in the same place for a long period of time, this helps establish you as a stable customer. Having a healthy income, with a budget that will be able to afford your monthly payments, will also work for you, and so will having a low debt to income ratio. If you still have some debt you are carrying with you, you'll want to take care of this before applying-it will help your credit score, as well.
By focusing on the positive, and building up more of it, you will be able to get a mortgage after bankruptcy.