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 7936875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:20:49+00:00 2026-06-03T22:20:49+00:00

Model: Field(‘text1′, type=’text’, length=1000, notnull=True) Function: def textinput(): f=SQLFORM(db.example, fields=[‘text1’]) if f.accepts(request.vars, session): return

  • 0

Model:

Field('text1', type='text', length=1000, notnull=True)

Function:

def textinput():
f=SQLFORM(db.example, fields=['text1'])
if f.accepts(request.vars, session):
return dict(form=f)

I want to be able to display the ‘text1’ field with proper line spacing/formatting. If a user was to press the [enter] key in the form to start a new line or whole new paragraph, I want this to reflect on the view.

For example, if a user enters the following into a SQLFORM:

This is a paragraph. Blah blah blah blah blah blah blah.
Blah blah blah blah blah blah blah blah blah.
Blah blah blah blah.

This is another paragraph. Blah blah blah blah blah.
Blah blah blah blah blah.

I want it to come out exactly like that in the view, instead of having it all crammed up with no spacing. How would I go about doing this? I was thinking about using the .replace method and replacing all [enter] keystrokes with a line break, but I’m not sure how to do it. I’ve searched all over Google but I can’t find my exact issue.

Any help would be greatly appreciated. Thanks.

  • 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-03T22:20:51+00:00Added an answer on June 3, 2026 at 10:20 pm

    The easiest method is to wrap the text in a <pre> tag and use CSS to control the styling. You can also replace the line breaks (‘\n’) with <br /> tags. If you are displaying the text via a readonly SQLFORM, a Crud read form, a SQLTABLE, or SQLFORM.grid, then you can set the field’s “represent” attribute to control the display:

    Using <pre>:

    Field('text1', type='text', length=1000, notnull=True,
        represent=lambda text, row: PRE(text))
    

    Using line break replacement:

    Field('text1', type='text', length=1000, notnull=True,
        represent=lambda text, row: XML(text.replace('\n', '<br />'),
            sanitize=True, permitted_tags=['br/']))
    

    If you’re inserting the text manually into a view, you can simply use either of the above methods directly in the view. For example:

    {{=PRE(row.text1)}}
    

    Note, browsers typically display text in a <pre> tag with a fixed-width font. If you don’t want that, you’ll need to use CSS to change the font.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've set my Model field to null=True , which allows NULL in MySQL, but
I wanted to write some code like this: class SomeModel(models.Model): field = models.ForeignKey(SomeOtherModel) def
I'm new from WebForms to MVC. I have view model field with the type
When we add a model field in Django we generally write: models.CharField(max_length=100, null=True, blank=True)
I have a problem when i try to create new model field type -
I have a Django model class with a non-model-field property, ex: def _get(self): return
What is the biggest integer the model field that this application instance can handle?
I'd like to have access to one my model field verbose_name. I can get
im trying to pass a generated choices to my model field, please where is
I want to display different forms in change_form depending on some model field's values.

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.