Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8302659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:20:31+00:00 2026-06-08T17:20:31+00:00

I have a table with address information. It has these fields. address_1 address_2 city

  • 0

I have a table with address information. It has these fields.

  • address_1
  • address_2
  • city
  • state
  • zip

No field is required. I want to display this in a template and format it nicely. I want line breaks between address_1, address_2, and the city/state/zip line for any of those that exists. I also want a comma between city and state if both exist. What is the best way to accomplish this? I started writing an if statement in the template, but it seemed to be getting a bit unwieldy. The big problem is that the user could enter only a city and state, only a zip code, a full-formed address, or anything between.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T17:20:32+00:00Added an answer on June 8, 2026 at 5:20 pm

    Many ways of achieving this, none are likely to be that elegant. I’ll throw this into the ring… Do this in your handler, and pass address_parts to the template context.

    ## Gather the address components in groups, removing any that are None
    address_parts = filter(None, [
        model_obj.address_1,
        model_obj.address_2,
        u', '.join(filter(None, [model_obj.address_city, model_obj.state])),
        model_obj.zip,
    ])
    
    
    ## In the template, join the address groups
    {{ address_parts|join:"<br>" }}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have address table in which city field have nvarchar datatype, but I want
I have a table with 3 address fields and each address field has a
i have a table of households which has the address information and city info
I have a table that has column names similar to ADDRESS, OLD_ADDRESS, CITY, OLD_CITY,
I have a table that has duplicate email address, I need to insert just
I have a table with name varchar address varchar country varchar city varchar .....
I have a table that displays information about a list of customers. I want
I have one table that includes company information (i.e. name, address, business description...) and
I have a social app that has a user_profile table with typical standard fields,
I have two domain classes (getter setter of two tables): Contact Information and Address

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.